Lorbat Lorbat - 2 months ago 17
SQL Question

Netezza SQL - order by an aggregate output

Select date, count(*) as volume
from table
group by date
order by 2
or
order by count
or
order by count(*)


The order by doesn't work for any of options above. I want order by volume

Can you help??

Answer

I just tried all the three queries on my Netezza and only two of them are working.

-- Working fine

   SELECT DATE, COUNT(*) AS VOLUME
   FROM TABLE
   GROUP BY DATE
   ORDER BY 2;

-- Working fine

   SELECT DATE, COUNT(*) AS VOLUME
   FROM TABLE
   GROUP BY DATE
   ORDER BY COUNT(*)

-- This is not working because Order by Column doesn't exist in the select clause.

   SELECT DATE, COUNT(*) AS VOLUME
   FROM TABLE
   GROUP BY DATE
   ORDER BY COUNT;