ozsenegal
ozsenegal

Reputation: 4133

Sql incorrect syntax

select max(qtd) 
from (select count(int_re_usu) as qtd from tb_questionario_voar_resposta)

Why this query dont work? I want to retrieve the max value from all count

it says incorrect syntax near')'

Any ideias?

Upvotes: 0

Views: 120

Answers (2)

Vishal
Vishal

Reputation: 12369

Try this you are missing a group by I think and use an alias-

     select 
              max(d1.qtd) 
        from 
        (
          select 
                count(int_re_usu) as qtd 
          from tb_questionario_voar_resposta
        group by qtd
        ) as d1
group by d1.qtd

Upvotes: 0

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171559

You need an alias on a derived table:

select max(qtd) 
from (
    select count(int_re_usu) as qtd 
    from tb_questionario_voar_resposta
) a

But as Vincent pointed out, that just returns one row, and I think you are missing a group by. You can really just do:

    select max(count(int_re_usu)) as qtd 
    from tb_questionario_voar_resposta
    group by SomeColumn

Upvotes: 3

Related Questions