ROLLUP

SQL ile Veri Odaklı Karar Verme

Bart Baesens

Professor Data Science and Analytics

renting_extended tablosu

renting_extended tablosunun ilk satırları:

| renting_id | country  | genre  | rating |
|------------|----------|--------|--------|
| 2          | Belgium  | Drama  | 10     |
| 32         | Belgium  | Drama  | 10     |
| 203        | Austria  | Drama  | 6      |
| 292        | Austria  | Comedy | 8      |
| 363        | Belgium  | Drama  | 7      |
| .......... | ........ | ...... | ...... |
SQL ile Veri Odaklı Karar Verme

ROLLUP ile sorgu

SELECT country, 
       genre, 
       COUNT(*)
FROM renting_extended
GROUP BY ROLLUP (country, genre);
  • Toplama seviyeleri
    • Her ülke-tür kombinasyonunun toplamı
    • Yalnızca ülke toplamı
    • Genel toplam
SQL ile Veri Odaklı Karar Verme

ROLLUP ile sorgu

SELECT country, 
       genre, 
       COUNT(*)
FROM renting_extended
GROUP BY ROLLUP (country, genre);
| country | genre  | count |
|---------|--------|-------|
| null    | null   | 22    |
| Austria | Comedy | 2     |
| Belgium | Drama  | 15    |
| Austria | Drama  | 4     |
| Belgium | Comedy | 1     |
| Belgium | null   | 16    |
| Austria | null   | 6     |
SQL ile Veri Odaklı Karar Verme

ROLLUP'ta sıra

SELECT country, 
       genre, 
       COUNT(*)
FROM renting_extended
GROUP BY ROLLUP (genre, country);
| country | genre  | count |
|---------|--------|-------|
| null    | null   | 22    |
| Austria | Comedy | 2     |
| Belgium | Drama  | 15    |
| Austria | Drama  | 4     |
| Belgium | Comedy | 1     |
| null    | Comedy | 3     |
| null    | Drama  | 19    |
SQL ile Veri Odaklı Karar Verme

ROLLUP özeti

  • Değer hiyerarşisi için toplamlar döndürür, ör. ROLLUP (country, genre)
    • Her ülke ve her tür için film kiralama
    • Her ülke için film kiralama
    • Toplam film kiralama sayısı
  • Her adımda bir ayrıntı seviyesi düşer
  • ROLLUP için sütun adlarının sırası önemlidir
SQL ile Veri Odaklı Karar Verme

Kiralama ve puan sayısı

SELECT country, 
       genre, 
       COUNT(*) AS n_rentals,
       COUNT(rating) AS n_ratings
FROM renting_extended
GROUP BY ROLLUP (genre, country);
| country  | genre  | n_rentals | n_ratings |
|----------|--------|-----------|-----------|
| null     | null   | 22        | 9         |
| Belgium  | Drama  | 15        | 6         |
| Austria  | Comedy | 2         | 1         |
| Belgium  | Comedy | 1         | 0         |
| Austria  | Drama  | 4         | 2         |
| null     | Comedy | 3         | 1         |
| null     | Drama  | 19        | 8         |
SQL ile Veri Odaklı Karar Verme

Haydi pratik yapalım!

SQL ile Veri Odaklı Karar Verme

Preparing Video For Download...