126k views
4 votes
Display items ordered for customer #10449, its standard price, and total price for all items ordered. Use label for Total Price. (HINT: Total price is Sum(quantity*price). Also, don’t forget the GROUP BY statement.

User Acorncom
by
7.4k points

1 Answer

2 votes

Answer:

Assuming you have a database with tables orders, order_details, and products with the necessary columns, here's an SQL query that retrieves the items ordered for customer #10449, their standard price, and the total price for all items ordered:

SELECT

products.productName AS ItemOrdered,

order_details.pricePerUnit AS StandardPrice,

SUM(order_details.quantity * order_details.pricePerUnit) AS TotalPrice

FROM

orders

INNER JOIN order_details ON orders.orderID = order_details.orderID

INNER JOIN products ON order_details.productID = products.productID

WHERE

orders.customerID = '10449'

GROUP BY

products.productName,

order_details.pricePerUnit;

Step-by-step explanation:

This query joins the orders, order_details, and products tables and filters the result to only include rows where the customerID is '10449'. It then groups the result by productName and pricePerUnit, and calculates the total price for each group using the SUM function.

The result will have three columns: ItemOrdered, StandardPrice, and TotalPrice, where ItemOrdered is the name of the product ordered, StandardPrice is the standard price for that product, and TotalPrice is the total price for all items of that product ordered by customer #10449. The TotalPrice column is labeled "Total Price" based on the instructions.

User Sekoul
by
8.0k points