Computer Science
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;
SQL Joins & Grouping
2 Likes
Answer
SELECT COUNT(DISTINCT STORE_ID) FROM SALES;
Explanation
SELECT COUNT(STORE_ID) FROM SALES;
— This query uses the COUNT() aggregate function with the STORE_ID column in the SELECT statement. It counts the number of non-null values in the STORE_ID column, and this count includes duplicates.SELECT COUNT(DISTINCT STORE_ID) FROM SALES;
— This option uses COUNT(DISTINCT STORE_ID) to count the number of unique store IDs in the SALES table. The DISTINCT keyword ensures that only distinct (unique) values are counted, avoiding overcounting due to duplicates.SELECT DISTINCT STORE_ID FROM SALES;
— This option selects distinct (unique) store IDs from the SALES table but does not count or provide the total number of stores.SELECT COUNT(STORE_ID) FROM SALES GROUP BY STORE_ID;
— This option attempts to count the number of occurrences of each store ID by using COUNT(STORE_ID) and grouping by store ID with GROUP BY STORE_ID. However, this results in a count for each unique store ID separately, not the total number of stores in the table.
Answered By
3 Likes
Related Questions
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;
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 allows you to find the total sales amount for Store ID 25 and the total sales amount for Store ID 45?
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES
WHERE STORE_ID IN (25, 45) GROUP BY STORE_ID; - SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES
GROUP BY STORE_ID HAVING STORE_ID IN (25, 45); - SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES WHERE STORE_ID IN (25, 45);
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES
WHERE STORE_ID = 25 AND STORE_ID = 45 GROUP BY STORE_ID;
- SELECT STORE_ID, SUM(SALES_AMOUNT) FROM SALES
Table EXAM_RESULTS
STU ID FNAME LNAME EXAM ID EXAM_SCORE 10 LAURA LYNCH 1 90 10 LAURA LYNCH 2 85 11 GRACE BROWN 1 78 11 GRACE BROWN 2 72 12 JAY JACKSON 1 95 12 JAY JACKSON 2 92 13 WILLIAM BISHOP 1 70 13 WILLIAM BISHOP 2 100 14 CHARLES PRADA 2 85 What SQL statement do we use to find the average exam score for EXAM_ID = 1?
- SELECT AVG(EXAM_SCORE) FROM EXAM_RESULTS;
- SELECT AVG(EXAM_SCORE) FROM EXAM_RESULTS GROUP BY EXAM_ID WHERE EXAM_ID = 1;
- SELECT AVG(EXAM_SCORE) FROM EXAM_RESULTS GROUP BY EXAM_ID HAVING EXAM_ID = 1;
- SELECT COUNT(EXAM_SCORE) FROM EXAM_RESULTS WHERE EXAM_ID = 1;