$pos = select * from score_history where content_id = 6 && val = 1
$neg = select * from score_history where content_id = 6 && val = -1
我想在一个查询中获得pos
和neg
分数,但我不想使用连接
所以也许是某种 IF/case 语句?
我有这个,但你可以猜到它失败了
SELECT count(*) as total ,
CASE
WHEN `val` = 1 THEN count(*) as `pos`
WHEN `val` = -1 THEN count(*) as `neg`
END
FROM score_history WHERE `content_id` = '46083' ";
有没有办法在不使用连接或子查询的情况下做到这一点?