Directions (Q96–100): A company is implementing a new database system to manage its customer information. The database contains tables for customers, orders, products and sales representatives. Each customer can place multiple orders and each order can contain multiple products. Each order is associated with a specific sales representative who manages the account. The database is designed to improve efficiency in tracking sales and customer interactions.
Which SQL query retrieves the total number of orders placed by a specific customer?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: B. SELECT COUNT(order_id) AS total_orders FROM orders WHERE customer_id = [Customer_ID];
Explanation
COUNT(order_id) counts the customer's order rows (non-NULL order ids). COUNT(*) would give the same result here; the keyed answer is the explicit COUNT(order_id). SUM(order_id) adds the ids, which is meaningless.More Database Management Systems questions
- Based on the passage, which of the following statements is true?
- Which of the following tables is most likely to have a foreign key referencing another table?
- Which SQL query retrieves the total number of distinct customers who have placed orders?
- Which of the following best describes the relationship between the 'orders' table and the 'customers' table?
- A ______ operation combines the rows of two relations and outputs a new relation that has both input relations' rows in it.
- Consider the relation R(P, Q, R, S, T, U, V, W, X, Y) and FDs: {P, Q, S} → T, R → Y, {P, Q} → V, {R, X} → X, Q → U, V → {W, X}. Which of th…