
Answer-first summary for fast verification
Answer: SELECT COUNT(*) FROM sales WHERE amount > 100;
The correct answer is **SELECT COUNT(*) FROM sales WHERE amount > 100;**. This query accurately counts all rows in the 'sales' table where the 'amount' column is greater than 100 by using the WHERE clause to filter rows before counting them with COUNT(*). - **Why not A or C?** While `COUNT_IF` might exist in some SQL dialects, it's not standard SQL and its behavior can vary. It's not the recommended way to count rows based on a condition. - **Why not D?** `COUNT(amount > 100)` counts the number of non-NULL results of the boolean expression `amount > 100`, which is not the same as counting rows where the amount exceeds 100.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
What is the correct SQL query to count the number of rows in a table named 'sales' where the 'amount' column exceeds 100?
A
SELECT COUNT_IF(amount > 100) FROM sales;
B
SELECT COUNT(*) FROM sales WHERE amount > 100;
C
SELECT COUNT_IF(amount > 100) AS count_above_100 FROM sales;
D
SELECT COUNT(amount > 100) FROM sales;
No comments yet.