Jump to content
Fórum Script Brasil
  • 0

Unpivot no MySql


thtrassi
 Share

Question

Olá galera, beleza?

Bom, quero a ajuda no seguinte item abaixo aonde tento trazer os número mais sorteados (10) e da erro. Pra ser bem sincero eu usava esse código no Firebird e funcionava normalmente, mas como estou me aventurando no MySql gostaria de fazer funcionar esse código.

 

public DataTable getResultadosMaisSorteados_Dez()
        {
            Cmd.CommandText = @"with CTE_Unpivot as
                                (    
                                    select cl_1 as dezena from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_2 from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_3 from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_4 from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_5 from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_6 from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_7 from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_8 from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_9 from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_10 from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_11 from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_12 from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_13 from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_14 from thsoftwares02.concurso_lotofacil
                                    union all
                                    select cl_15 from thsoftwares02.concurso_lotofacil
                                )

                                select first 10
                                    Dezena,
                                    COUNT(*) as Qtd
                                from CTE_Unpivot
                                group by
                                    Dezena
                                order by
                                    Qtd desc";

            DataTable dt = ExecutaSelect();
            return dt;
        }

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.6k
    • Total Posts
      646.2k
×
×
  • Create New...