mysql counts the number of occurrences of a certain value in a column without using where

SELECT article_id,COUNT(article_like = 1 or null) AS like_count,
	   COUNT(article_like = 2 or null) AS dislike_count 
FROM ...

Put the condition in count. If it is true, it will be counted once. If it is false, it will be null and it will not be counted.

Guess you like

Origin blog.csdn.net/ZHAI_KE/article/details/131591956
Recommended