DATA_ENGINEERETTE Telegram 416
ROLLUP vs CUBE vs GROUPING SETS

Суть этих штук - добавить промежуточные тоталы (как в экселе). Как будто мы group by делаем несколько раз с разными полями

🍣 ROLLUP

GROUP BY ROLLUP (country, region, city)


country-region-city - 6 строк
country-region - 4 строки
country - 2 строки
all - 1 строка
————
13 строк

Мы с каждым уровнем отбрасываем более детальный столбец и считаем тотал шире

Первые 6 строк - как в обычной группировке (поэтому не расписываю). К ним еще добавляем тоталы по стране с регионом, стране и глобальный тотал:

Russia Moscow Oblast NULL 12800
Russia Siberia NULL 1600
USA California NULL 4900
USA Texas NULL 2300
Russia NULL NULL 14400
USA NULL NULL 7200
NULL NULL NULL 21600


🎲 CUBE

GROUP BY CUBE (country, region, city)


Здесь нужны все комбинации: по 3 элемента, 2, 1, 0

country-region-city - 6 строк
country-region - 4 строк
country-city - 6 строк
region-city - 6 строк
country - 2 строки
region - 4 строки
city - 6 строк
all - 1 строка
————
35 строк

👥 GROUPING SETS

GROUP BY GROUPING SETS ((country, region, city), (country, region), (country), ())


Здесь можно кастомно задавать группы. В этом примере будет то же самое, что и ROLLUP
Please open Telegram to view this post
VIEW IN TELEGRAM
18👍9🔥6



tgoop.com/data_engineerette/416
Create:
Last Update:

ROLLUP vs CUBE vs GROUPING SETS

Суть этих штук - добавить промежуточные тоталы (как в экселе). Как будто мы group by делаем несколько раз с разными полями

🍣 ROLLUP

GROUP BY ROLLUP (country, region, city)


country-region-city - 6 строк
country-region - 4 строки
country - 2 строки
all - 1 строка
————
13 строк

Мы с каждым уровнем отбрасываем более детальный столбец и считаем тотал шире

Первые 6 строк - как в обычной группировке (поэтому не расписываю). К ним еще добавляем тоталы по стране с регионом, стране и глобальный тотал:

Russia Moscow Oblast NULL 12800
Russia Siberia NULL 1600
USA California NULL 4900
USA Texas NULL 2300
Russia NULL NULL 14400
USA NULL NULL 7200
NULL NULL NULL 21600


🎲 CUBE

GROUP BY CUBE (country, region, city)


Здесь нужны все комбинации: по 3 элемента, 2, 1, 0

country-region-city - 6 строк
country-region - 4 строк
country-city - 6 строк
region-city - 6 строк
country - 2 строки
region - 4 строки
city - 6 строк
all - 1 строка
————
35 строк

👥 GROUPING SETS

GROUP BY GROUPING SETS ((country, region, city), (country, region), (country), ())


Здесь можно кастомно задавать группы. В этом примере будет то же самое, что и ROLLUP

BY дата инженеретта


Share with your friend now:
tgoop.com/data_engineerette/416

View MORE
Open in Telegram


Telegram News

Date: |

The optimal dimension of the avatar on Telegram is 512px by 512px, and it’s recommended to use PNG format to deliver an unpixelated avatar. Just at this time, Bitcoin and the broader crypto market have dropped to new 2022 lows. The Bitcoin price has tanked 10 percent dropping to $20,000. On the other hand, the altcoin space is witnessing even more brutal correction. Bitcoin has dropped nearly 60 percent year-to-date and more than 70 percent since its all-time high in November 2021. SUCK Channel Telegram How to Create a Private or Public Channel on Telegram? Telegram message that reads: "Bear Market Screaming Therapy Group. You are only allowed to send screaming voice notes. Everything else = BAN. Text pics, videos, stickers, gif = BAN. Anything other than screaming = BAN. You think you are smart = BAN.
from us


Telegram дата инженеретта
FROM American