Skip to main content
removeu 4 caracteres do conteúdo
Fonte Link
cantoni
  • 6,8mil
  • 17
  • 36

Você não pode usar o nome de uma coluna apelidada com as no Group By. Tente isso:

select ESCALAO,COUNT(*) AS QTD
from
(
    select 
            case
              when sal BETWEEN 0 and 100000 then 1
              when sal BETWEEN 100001 and 200000 then 2
              when sal BETWEEN 200001 and 300000 then 3
              when sal BETWEEN 300001 and 400000 then 4
            else 5 END AS 'ESCALAO'
    FROM EMP
)
GROUP BY ESCALAO
ORDER BY QTD DESC;

Você não pode usar o nome de uma coluna apelidada com as no Group By. Tente isso:

select ESCALAO,COUNT(*) AS QTD
from
(
    select 
            case
              when sal BETWEEN 0 and 100000 then 1
              when sal BETWEEN 100001 and 200000 then 2
              when sal BETWEEN 200001 and 300000 then 3
              when sal BETWEEN 300001 and 400000 then 4
            else 5 END AS 'ESCALAO'
    FROM EMP
)
GROUP BY ESCALAO
ORDER BY QTD DESC;

Você não pode usar o nome de uma coluna apelidada com as no Group By. Tente isso:

select ESCALAO,COUNT(*) AS QTD
from
(
    select 
        case
          when sal BETWEEN 0 and 100000 then 1
          when sal BETWEEN 100001 and 200000 then 2
          when sal BETWEEN 200001 and 300000 then 3
          when sal BETWEEN 300001 and 400000 then 4
          else 5 END AS 'ESCALAO'
    FROM EMP
)
GROUP BY ESCALAO
ORDER BY QTD DESC;
Fonte Link
cantoni
  • 6,8mil
  • 17
  • 36

Você não pode usar o nome de uma coluna apelidada com as no Group By. Tente isso:

select ESCALAO,COUNT(*) AS QTD
from
(
    select 
            case
              when sal BETWEEN 0 and 100000 then 1
              when sal BETWEEN 100001 and 200000 then 2
              when sal BETWEEN 200001 and 300000 then 3
              when sal BETWEEN 300001 and 400000 then 4
            else 5 END AS 'ESCALAO'
    FROM EMP
)
GROUP BY ESCALAO
ORDER BY QTD DESC;