Created
April 18, 2020 20:53
-
-
Save flutesa/0b1a6e19ca0b0c18e8828ace4ed780a9 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
1) | |
select users.first_name, users.last_name, users.email, count(orders.orders_id) as order_number | |
from [DZ1.users] users | |
left join [DZ1.orders] orders | |
on orders.user_id = users.id | |
group by orders.user_id, users.first_name, users.last_name, users.email | |
order by order_number desc | |
limit 5 | |
2) | |
select users.country, sum(orders.order_sum) as total_sum | |
from `DZ1.users` users | |
left join `DZ1.orders` orders | |
on orders.user_id = users.id | |
where users.country = 'Russia' or users.country = 'Brazil' | |
group by users.country | |
order by total_sum desc | |
limit 1 | |
3) | |
select count(users.email) as no_data | |
from `DZ1.users` users | |
left join `DZ1.orders` orders | |
on users.id = orders.orders_id | |
where orders.user_id is null | |
4) | |
select count(*) as no_user_data | |
from `DZ1.users` users | |
right join `DZ1.orders` orders | |
on users.id = orders.orders_id | |
where users.id is null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment