Skip to content

Instantly share code, notes, and snippets.

@georgewfraser
Created September 13, 2022 01:04
Show Gist options
  • Save georgewfraser/9f3aad9cd3d8a63d2ec102e1656c51b0 to your computer and use it in GitHub Desktop.
Save georgewfraser/9f3aad9cd3d8a63d2ec102e1656c51b0 to your computer and use it in GitHub Desktop.
select
state,
sum(total_cost),
sum(quantity)
from orders
join order_items using (order_id)
join customer using (customer_id)
group by 1
select
state,
sum(distinct hash(order_id) + total_cost) - sum(distinct hash(order_id)),
sum(quantity)
from orders
join order_items using (order_id)
join customer using (customer_id)
group by 1
sum(distinct hash(order_id) + total_cost) - sum(distinct hash(order_id))
select
state,
sum(total_cost),
sum(quantity)
from orders
join (
select order_id, sum(quantity) as quantity
from order_items
group by 1
) using (order_id)
join customers using (customer_id)
group by 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment