Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

SQL HELP!! Question: Pictures of Database: Previous query: SELECT customer.c_nam

ID: 3830805 • Letter: S

Question

SQL HELP!!

Question:

Pictures of Database:

Previous query:

SELECT
customer.c_name,
customer.c_custkey,
count(o_orderKey) as count,
avg(orders.O_TOTALPRICE) as total_value,
min(orders.O_TOTALPRICE) as min_value,
max(orders.O_TOTALPRICE) as max_value

FROM customer INNER JOIN orders on orders.O_CUSTKEY = customer.c_custkey
group by customer.c_name, customer.c_custkey
order by customer.c_custkey, customer.c_name

6. Finally, let's clean up the prior query by using some better names for our fields In SQL these are called an "alias". See this link for an uickref.asp Modify your query to do the following: Customer ID Total Orders Average Orders Min Order Max Order Customer 000000001 1 9 158763.734444 28599.83 357345.46 Customer#0000000002 2 10 115650.492000 37156.97 201568.55 Customer#000000004 4 31 133373.141613 6829.14 275581.07 Customer#0000000055 9 120449.193333 29999.18 271505.25 Customer#0000000077 24 163417.540833 34119.28 354885.81 Customer#000000008 8 14 165114.196429 57858.41 256717.52 Customer#000000010 10 27 143151.784444 6751.57 322342.37 Customer#000000011 11 7 176212.361429 16873.08 302431.56 Customer 000000013 13 21 109182.598571 23620.23 304442.62 Customer#000000014 14 11 162487.189091 27393.03 248409.17

Explanation / Answer

SELECT
'Customer#' || customer.c_name as Customer ,
customer.c_custkey as ID,
count(o_orderKey) as "Total Orders",
avg(orders.O_TOTALPRICE) as "Average Orders",
min(orders.O_TOTALPRICE) as "Min Order",
max(orders.O_TOTALPRICE) as "Max Order"

FROM customer INNER JOIN orders on orders.O_CUSTKEY = customer.c_custkey
group by customer.c_name, customer.c_custkey
order by customer.c_custkey, customer.c_name;