SQL Help!!
Three part question:
1. List Top 10 customers by their names who ordered the most quantity and their country of origin. (double inner join)
2. List top 5 customers of from Canada that placed the most orders (quantity). (double inner join)
3. Order top 20 customer from United States and China who placed the most order (Quantity) according to their order date from earliest to latest. Also, report the country of origin.
Photos of the database below:
Expert Answer
2.Select c.c_name,sum(l.quantity) AS Sum_Quantity, n.n_name From customer c Inner Join Nation n on c.c_nationkey=n.n_nationkey Inner Join Orders on o.o_custkey=c.c_custkey Inner join lineitem l on l.orderkey=o.o_orderkey where n.n_name=’Canada’ group by l.l_orderkey order by Sum_Quantity Desc Limit 5.
3.Select c.c_name,sum(l.quantity) AS Sum_Quantity, n.n_name From customer c Inner Join Nation n on c.c_nationkey=n.n_nationkey Inner Join Orders on o.o_custkey=c.c_custkey Inner join lineitem l on l.orderkey=o.o_orderkey where n.n_name in (‘United States’,’China’) group by l.l_orderkey order by Sum_Quantity Desc,o.o_orderdate Asc Limit 20.