Skip to content

Instantly share code, notes, and snippets.

@AndreyBespamyatnov
Created November 16, 2017 13:04
Show Gist options
  • Save AndreyBespamyatnov/09dad7f0350e15bffcb2652d2644eb77 to your computer and use it in GitHub Desktop.
Save AndreyBespamyatnov/09dad7f0350e15bffcb2652d2644eb77 to your computer and use it in GitHub Desktop.
-- a- list of clients, which have an order with order_sum > 50
select c.client_id, c.client_name from Clients as c
inner join Orders as o on o.client_id = c.client_id
where o.order_sum > 50
-- b- clients, whose total sum of orders exceeds 100
Select * from
(select c.client_id, c.client_name, SUM(o.order_sum) as total from Clients as c
inner join Orders as o on o.client_id = c.client_id
GROUP BY c.client_id) as t
where total > 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment