Having
WHERE is used to filter rows before any grouping occurs. Once you have performed a grouping operation, you may want to further restrict the number of rows returned. This is a job for HAVING.
In this exercise, you will modify an existing query to use HAVING, so that only those results with a sum of over 10000 are returned.
Latihan ini adalah bagian dari kursus
Introduction to SQL Server
Petunjuk latihan
- Modify the provided query to remove the
WHEREclause. - Replace it with a
HAVINGclause so that only results with a totaldemand_loss_mwof greater than10000are returned.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
SELECT
nerc_region,
SUM (demand_loss_mw) AS demand_loss
FROM
grid
-- Remove the WHERE clause
WHERE demand_loss_mw IS NOT NULL
GROUP BY
nerc_region
-- Enter a new HAVING clause so that the sum of demand_loss_mw is greater than 10000
___
___(demand_loss_mw) > ___
ORDER BY
demand_loss DESC;