Created
September 13, 2022 01:04
-
-
Save georgewfraser/9f3aad9cd3d8a63d2ec102e1656c51b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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