Data Lake • Write your own SQL

Sort into sizes and see the spread

How many small, medium and large orders are there?

Try this

  • Run this on my data lake: SELECT CASE WHEN amount < 15 THEN 'small' WHEN amount < 50 THEN 'medium' ELSE 'large' END AS size, COUNT(*) AS orders, median(amount) AS middle, approx_percentile_cont(amount, 0.9) AS p90 FROM samples.shop_orders GROUP BY 1 ORDER BY 2 DESC

In plain words

What is it?

You make your own groups, then look at what is typical in each.

How does it work?

CASE gives each row a label. median finds the middle value, and approx_percentile_cont finds the value that 90 percent fall under.

Good to know

The percentile is an estimate. The median tells you more than the average when a few values are huge.

Then try

Customers, average, middle and spread by region

  • Run this on my data lake: SELECT region, COUNT(DISTINCT customer_id) AS customers, AVG(amount) AS average, median(amount) AS middle, stddev(amount) AS spread FROM samples.shop_orders GROUP BY region ORDER BY region