Sql query to Count 0s and 1s with Case #sql #database #sqltips #interview #databaseconcepts #views

preview_player
Показать описание
COUNT(CASE WHEN value = 0 THEN 1 END): Counts rows where value is 0. The CASE statement returns 1 when the condition is true (i.e., value = 0), and NULL otherwise. COUNT only counts non-NULL values, so this effectively counts the number of 0s.
COUNT(CASE WHEN value = 1 THEN 1 END): Similarly, counts rows where value is 1.
Рекомендации по теме
welcome to shbcf.ru