BaşlayınÜcretsiz Başlayın

GROUP BY

In an earlier exercise, you wrote a separate WHERE query to determine the amount of demand lost for a specific region. We wouldn't want to have to write individual queries for every region. Fortunately, you don't have to write individual queries for every region. With GROUP BY, you can obtain a sum of all the unique values for your chosen column, all at once.

You'll return to the grid table here and calculate the total lost demand for all regions.

Bu egzersiz

Introduction to SQL Server

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Select nerc_region and the sum of demand_loss_mw for each region.
  • Exclude values where demand_loss_mw is NULL.
  • Group the results by nerc_region.
  • Arrange in descending order of demand_loss.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

-- Select the region column
SELECT 
  ___,
  -- Sum the demand_loss_mw column
  SUM(___) AS demand_loss
FROM 
  grid
  -- Exclude NULL values of demand_loss
WHERE 
  demand_loss_mw ___ ___ ___
  -- Group the results by nerc_region
___ __ 
  nerc_region
  -- Order the results in descending order of demand_loss
ORDER BY 
  demand_loss ___;
Kodu Düzenle ve Çalıştır