Jump to content
Fórum Script Brasil
  • 0

Unpivot no Postgres 9.3


thtrassi
 Share

Question

Olá pessoal do Postgres. Tenho esse código abaixo que utilizava no Firebid pra trazer os 10 números mais sorteados e ao utilizar no Postgres não deu certo. Alguém pode ajudar?

 

with unpivot as
(    
    select cl_1 as dezena from concurso_lotofacil
    union all
    select cl_2 from concurso_lotofacil
    union all
    select cl_3 from concurso_lotofacil
    union all
    select cl_4 from concurso_lotofacil
    union all
    select cl_5 from concurso_lotofacil
    union all
    select cl_6 from concurso_lotofacil
    union all
    select cl_7 from concurso_lotofacil
    union all
    select cl_8 from concurso_lotofacil
    union all
    select cl_9 from concurso_lotofacil
    union all
    select cl_10 from concurso_lotofacil
    union all
    select cl_11 from concurso_lotofacil
    union all
    select cl_12 from concurso_lotofacil
    union all
    select cl_13 from concurso_lotofacil
    union all
    select cl_14 from concurso_lotofacil
    union all
    select cl_15 from concurso_lotofacil
)
select first 10
    Dezena,
    COUNT(*) as Qtd
from unpivot
group by
    Dezena
order by
    Qtd desc

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

No postgresql, não usa first 10, usa limit 10 no final da consulta.

tente assim:

with unpivot as
(    
    select cl_1 as dezena from concurso_lotofacil
    union all
    select cl_2 from concurso_lotofacil
    union all
    select cl_3 from concurso_lotofacil
    union all
    select cl_4 from concurso_lotofacil
    union all
    select cl_5 from concurso_lotofacil
    union all
    select cl_6 from concurso_lotofacil
    union all
    select cl_7 from concurso_lotofacil
    union all
    select cl_8 from concurso_lotofacil
    union all
    select cl_9 from concurso_lotofacil
    union all
    select cl_10 from concurso_lotofacil
    union all
    select cl_11 from concurso_lotofacil
    union all
    select cl_12 from concurso_lotofacil
    union all
    select cl_13 from concurso_lotofacil
    union all
    select cl_14 from concurso_lotofacil
    union all
    select cl_15 from concurso_lotofacil
)
select 
    Dezena,
    COUNT(*) as Qtd
from unpivot
group by
    Dezena
order by
    Qtd desc
    limit 10

 

Link to comment
Share on other sites

  • 0

No postgresql, não usa first 10, usa limit 10 no final da consulta.

tente assim:

with unpivot as
(    
    select cl_1 as dezena from concurso_lotofacil
    union all
    select cl_2 from concurso_lotofacil
    union all
    select cl_3 from concurso_lotofacil
    union all
    select cl_4 from concurso_lotofacil
    union all
    select cl_5 from concurso_lotofacil
    union all
    select cl_6 from concurso_lotofacil
    union all
    select cl_7 from concurso_lotofacil
    union all
    select cl_8 from concurso_lotofacil
    union all
    select cl_9 from concurso_lotofacil
    union all
    select cl_10 from concurso_lotofacil
    union all
    select cl_11 from concurso_lotofacil
    union all
    select cl_12 from concurso_lotofacil
    union all
    select cl_13 from concurso_lotofacil
    union all
    select cl_14 from concurso_lotofacil
    union all
    select cl_15 from concurso_lotofacil
)
select 
    Dezena,
    COUNT(*) as Qtd
from unpivot
group by
    Dezena
order by
    Qtd desc
    limit 10

 

Perfeito amigo, vou testar na aplicação, mas deu certo. Obrigado

Link to comment
Share on other sites

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...