OLAP: CUBE-Operator

Datengestützte Entscheidungsfindung in SQL

Irene Ortner

Data Scientist at Applied Statistics

Einführung in OLAP

  • OLAP: Online Analytical Processing
  • Aggregieren von Daten für besseren Überblick
    • Zählen der Ausleihen pro Person
    • Durchschnittliche Filmbewertung je Genre und Land
  • Erstellen von Pivot-Tabellen zur Darstellung der Aggregations-Ergebnisse
Datengestützte Entscheidungsfindung in SQL

Tabelle rentings_extended

| 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      |
| .......... | ....... | .....  | ...... |
Datengestützte Entscheidungsfindung in SQL

Pivot-Tabelle – Anzahl der Filmausleihen

 

 

Datengestützte Entscheidungsfindung in SQL

Pivot-Tabelle und SQL-Ausgabe

Datengestützte Entscheidungsfindung in SQL

GROUP BY CUBE

SELECT country, 
       genre, 
       COUNT(*)
FROM renting_extended
GROUP BY CUBE (country, genre);
| country  | genre  | count |
|----------|--------|-------|
| Austria  | Comedy | 2     |
| Belgium  | Drama  | 15    |
| Austria  | Drama  | 4     |
| Belgium  | Comedy | 1     |
| Belgium  | null   | 16    |
| Austria  | null   | 6     |
| null     | Comedy | 3     |
| null     | Drama  | 19    |
| null     | null   | 22    |
Datengestützte Entscheidungsfindung in SQL

Anzahl der Bewertungen

SELECT country, 
       genre, 
       COUNT(rating)
FROM renting_extended
GROUP BY CUBE (country, genre);
| country  | genre  | count |
|----------|--------|-------|
| Austria  | Comedy | 1     |
| Belgium  | Drama  | 6     |
| Austria  | Drama  | 2     |
| Belgium  | Comedy | 0     |
| Belgium  | null   | 6     |
| Austria  | null   | 3     |
| null     | Comedy | 1     |
| null     | Drama  | 8     |
| null     | null   | 9     |
Datengestützte Entscheidungsfindung in SQL

Lass uns üben!

Datengestützte Entscheidungsfindung in SQL

Preparing Video For Download...