HAVING Clause Usage

August 15, 2017 ยท View on GitHub

Consider removing the HAVING clause:

Rewriting the query's HAVING clause into a predicate will enable the use of indexes during query processing.

Example

SELECT s.cust_id,count(s.cust_id) FROM SH.sales s GROUP BY s.cust_id
HAVING s.cust_id != '1660' AND s.cust_id != '2'

can be rewritten as:

SELECT s.cust_id,count(cust_id) FROM SH.sales s WHERE s.cust_id != '1660'
AND s.cust_id !='2' GROUP BY s.cust_id