SQL Playground

Write SQL against a sample shop database and run it. PostgreSQL runs here in your browser, so nothing you do reaches a server: insert, update, drop tables, and reset the database whenever you like.

Loading…

select c.country, count(*) as orders, sum(oi.quantity * oi.unit_price) as revenue
from orders o
join customers c on c.customer_id = o.customer_id
join order_items oi on oi.order_id = o.order_id
where o.status <> 'cancelled'
group by c.country
order by revenue desc;

Tables