About SQL’s “Having”
Something I SHOULD have been using a long time ago!
this is the SQL Syntax of “Having” (link is to Snowflake Doc)
For me, it can be used instead of a more elaborate “Where”.
Looking forward to using this and seeing how it can be used effectively, consulting the article by geeksforgeeks it below are worth remembering…
we use WHERE prior to GROUP BY and HAVING after GROUP BY.
The Where clause acts as a pre filter where as Having as a post filter.
https://www.geeksforgeeks.org/having-vs-where-clause-in-sql/
select serial_number, count(reports) from one_db.plm.warranty_list group by ser_no_prm having count(reports) > 2;
My old habit would’ve achieved the same result but with a nested query….
---achieving same without using 'having' select * from ( select serial_nbr, count(reports) as qty from one_db.plm.warranty_list group by serial_nbr ) where qty > 2;