Answered! SQL Help!! Three part question: 1. List Top 10 customers by their names who ordered the most quantity and their country of origin….

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. This question should be the following format:

c custkey c name SUM(lineitem.l quantity) o DATE n name 1992-04-05 UNITED STATES 619 Customer#000000619 2609

Photos of the database below:

Expert Answer

 1.

Select TOP 10 c_name ,n_name from customer inner join nation on customer.c_nationkey = nation.n_nationkey inner join orders on customer.c_custkey = orders.o_custkey inner join lineitem on lineitem.l_orderkey = orders.o_orderkey order by lineitem.l_quantity desc;

2.

Select TOP 5 customer.c_custkey,c_name from customer inner join nation on customer.c_nationkey = nation.n_nationkey inner join orders on customer.c_custkey = orders.o_custkey inner join lineitem on lineitem.l_orderkey = orders.o_orderkey where nation.n_name = ‘CANADA’ order by lineitem.l_quantity desc;

3

Select TOP 20 c_custkey c_name ,SUM(lineitem.l_quantity),o_date,n_name from customer inner join nation on customer.c_nationkey = nation.n_nationkey inner join orders on customer.c_custkey = orders.o_custkey inner join lineitem on lineitem.l_orderkey = orders.o_orderkey where n_name = ‘UNITED STATES’ or n_name = ‘CHINA’ order by o_date;

Still stressed from student homework?
Get quality assistance from academic writers!