I have the following sql statement:
select val, count(*) as tally from sometable group by val order by tally desc
Which produces the following (example) table:
val | tally
----+-------
4 | 20
5 | 10
6 | 5
7 | 3
8 | 2
Now, I want to only display the rows where tally > 5, so the result will be:
val | tally
----+-------
4 | 20
5 | 10
I tried this statement, but it does not work (it says “tally” is unknown):
select val, count(*) as tally from sometable where tally > 5 group by val order by tally desc
Try HAVING (more information):