Pages

Friday, July 12, 2013

mysql count like and dislike average from one column


likes_id video_id Descending user_id like_status like_ip datetime
13 290 2 y 2013-07-01 17:15:29
25 290 3 y 2013-07-01 17:26:12
42 290 9 y 2013-07-01 17:30:35
58 290 10 n 183.182.91.153 2013-07-12 04:52:44

SELECT `like_status` , count( * ) FROM video_likes WHERE video_id = 290 GROUP BY `like_status`



like_status count( * )
y 3
n 1

SELECT SUM( CASE WHEN like_status = 'y' THEN 1 ELSE -1 END) as `counts` FROM `wp_video_likes`  WHERE video_id = 290;

No comments: