CODE WORKSPACE

Hot partition skew

Return partition_day, row_count, and skew_flag ('hot' when row_count is above the average, else 'normal'). Order by row_count DESC, then partition_day.

Label each partition hot or normal by comparing its row_count to the table average.

Sample input

table_partitionsAverage row count is 1625; two days sit well above it.
partition_dayrow_count
2026-01-01900
2026-01-021100
2026-01-03800
2026-01-044200
2026-01-051000
2026-01-063000
2026-01-071200
2026-01-08800

Expected output

Expected outputEach partition flagged hot or normal versus the average, largest first.
partition_dayrow_countskew_flag
2026-01-044200hot
2026-01-063000hot
2026-01-071200normal
2026-01-021100normal
2026-01-051000normal
2026-01-01900normal
2026-01-03800normal
2026-01-08800normal

Constraints

Compare row_count to (SELECT AVG(row_count) FROM table_partitions) inside a CASE to label hot vs normal. Order by row_count DESC, partition_day ASC.

Expected skills

Skew detection with a scalar AVG and CASE labels.

SQL
Loading...

AI evaluation

Run the SQL query to inspect preview rows.