Computer Science
Table SALES
Column Name |
---|
STORE_ID |
SALES_DATE |
SALES_AMOUNT |
Which SQL statement lets you find the sales amount for each store?
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES;
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES ORDER BY STORE_ID;
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES GROUP BY STORE_ID;
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES HAVING UNIQUE STORE_ID;
Answer
SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES GROUP BY STORE_ID;
Explanation
SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES;
— This statement selects the store_ID and calculates the total sales amount using SUM() aggregate function from the SALES table. It does not group the results by store ID, so it will return a single row with the total sales amount across all stores.SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES ORDER BY STORE_ID;
— This statement selects the store_ID and calculates the total sales amount using SUM() aggregate function from the SALES table and uses an ORDER BY clause to sort the results by store ID. However, it still doesn't group the results by store_ID.SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES GROUP BY STORE_ID;
— This statement selects the store_ID and calculates the total sales amount using SUM() aggregate function from the SALES table and uses the GROUP BY clause to group the results by store ID. It calculates the total sales amount for each store ID separately. As a result, it calculates the total sales amount for each unique store ID separately, providing a breakdown of sales amounts for each store in the dataset.SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES HAVING UNIQUE STORE_ID;
— This statement is incorrect because the HAVING clause is used for filtering grouped data based on a condition, not for identifying unique values. Also, "UNIQUE STORE_ID" is not a valid condition in SQL.
Related Questions
What are most common types of SQL joins ?
Table BOOK_INFORMATION
Column Name BOOK_ID BOOK_TITLE PRICE Which SQL statement allows you to find the highest price from the table BOOK_INFORMATION?
- SELECT BOOK_ID, BOOK_TITLE, MAX(PRICE) FROM BOOK_INFORMATION;
- SELECT MAX(PRICE) FROM BOOK_INFORMATION;
- SELECT MAXIMUM(PRICE) FROM BOOK_INFORMATION;
- SELECT PRICE FROM BOOK_INFORMATION ORDER BY PRICE DESC;
Table SALES
Column Name STORE_ID SALES_DATE SALES_AMOUNT Which SQL statement lets you list all stores whose total sales amount is over 5000 ?
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES GROUP BY STORE_ID HAVING SUM(SALES_AMOUNT) > 5000;
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES GROUP BY STORE_ID HAVING SALES_AMOUNT > 5000;
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES
WHERE SUM(SALES_AMOUNT) > 5000 GROUP BY STORE_ID; - SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES
WHERE SALES_AMOUNT > 5000 GROUP BY STORE_ID;
Table SALES
Column Name STORE_ID SALES_DATE SALES_AMOUNT Which SQL statement lets you find the total number of stores in the SALES table?
- SELECT COUNT(STORE_ID) FROM SALES;
- SELECT COUNT(DISTINCT STORE_ID) FROM SALES;
- SELECT DISTINCT STORE_ID FROM SALES;
- SELECT COUNT(STORE_ID) FROM SALES GROUP BY STORE_ID;