191k views
4 votes
You have been asked to create a report that lists all corporate customers and all orders that they have placed. The customers should be listed alphabetically beginning with the letter 'a', and their corresponding order totals should be sorted from the highest amount to the lowest amount. Which of the following statements should you issue?

A. ```sql
SELECT customer_name, order_total
FROM customers
JOIN orders ON customers.customer_id = orders.customer_id
ORDER BY customer_name ASC, order_total DESC;

B. ```sql
SELECT customer_name, order_total
FROM orders
JOIN customers ON customers.customer_id = orders.customer_id
ORDER BY customer_name ASC, order_total DESC;

C. ```sql
SELECT customer_name, order_total
FROM customers
LEFT JOIN orders ON customers.customer_id = orders.customer_id
ORDER BY customer_name ASC, order_total DESC;

D. ```sql
SELECT customer_name, order_total
FROM orders
LEFT JOIN customers ON customers.customer_id = orders.customer_id
ORDER BY customer_name ASC, order_total DESC;

User Pinglock
by
8.2k points

1 Answer

2 votes

Final answer:

The correct SQL statement for listing corporate customers and their orders alphabetically and by descending order totals is Option A. This option sorts customer names in ascending order and order totals in descending order, while also correctly joining the two tables.

Step-by-step explanation:

The correct option : c

The correct SQL statement to use in order to create a report that lists all corporate customers alphabetically and their corresponding orders from the highest to the lowest amount.

SELECT customer_name, order_total
FROM customers
JOIN orders ON customers.customer_id = orders.customer_id
ORDER BY customer_name ASC, order_total DESC;

This SQL statement will list all customers alphabetically as it orders customer_name with 'ASC' (ascending), and sorts their order totals from the highest to the lowest as it orders order_total with 'DESC' (descending). When using a JOIN clause, it's common to start with the table that contains the primary key, which is assumed to be customers in this scenario. The option that starts with the orders table and uses a LEFT JOIN could potentially include orders without associated customers, or if the customers do not have orders, which would not properly fulfill the report’s requirements.

User Xxxmatko
by
7.6k points