5.22
Given relation s(a,b,c), write an SQL statement to generate a histogram showing the sum of c values versus a, dividing a into 20 equal-sized partitions (i.e., where each partition contains 5 percent of tuples in s, sorted by a).
WITH s_with_partition(a,b,c,partion_id) AS (
SELECT a,b,c,NTILE(20) OVER (ORDER BY (a) ASC) AS partition_id
FROM s
)SELECT partition_id,SUM(c)
FROM s_with_partition
GROUP BY partition_id
ORDER BY partition_id;