I have following simple sql code to select the number of rows that meet a specific criteria:
SELECT COUNT(CASE WHEN /*condition*/ THEN 1 END) FROM table_name;
Verus
SELECT COUNT(*) FROM table_name WHERE /*condition*/;
Both of them seems to work the same when I only want to do some aggregate function to the data.
I have two questions:
- Which one has faster performance speed?
- Which one is commonly preferable by developers (when doing aggregate function)?
Thanks for any responds!