The difference between the WHERE and HAVING clauses is the scope: WHERE filters the basic rows, and HAVING filters the grouped result set. WHERE is used for single row conditions and HAVING is used for group result conditions. WHERE comes after FROM and before SELECT, HAVING comes after GROUP BY. WHERE can be used alone, HAVING must be used with a group operation.
The difference between WHERE and HAVING clauses in Oracle
WHERE and HAVING are two SQL clauses, use to filter the data set. The main difference between them is their scope:
1. Scope
2. Usage scenarios
<code class="sql">SELECT * FROM products WHERE price > 100;</code>
<code class="sql">SELECT category, AVG(price) AS avg_price FROM products GROUP BY category HAVING avg_price > 100;</code>
3. Location
4. Example
<code class="sql">-- 使用 WHERE 子句过滤行 SELECT * FROM orders WHERE customer_id = 1; -- 使用 HAVING 子句过滤组 SELECT product_category, SUM(quantity) AS total_quantity FROM order_details GROUP BY product_category HAVING total_quantity > 100;</code>
Note:
The above is the detailed content of The difference between where and having in oracle. For more information, please follow other related articles on the PHP Chinese website!