我有三个这样的表:
漫画
| id | sendby
------------------
| 1 | 1
| 2 | 1
| 3 | 1
| 4 | 1
小伙子
| id | sendby | translator | graphic
-------------------------------------------
| 1 | 1 | admin | other
| 2 | 1 | admin | other
| 3 | 1 | admin | admin
| 4 | 1 | other | admin
用户
| userid | username
-----------------------
| 1 | admin
我试图计算我发送过的内容,但结果不正确。
我试过以下查询:
SELECT username,
SUM(
CASE WHEN m.sendby = u.userid
THEN 1 ELSE 0 END
) AS manga,
SUM(
CASE WHEN c.sendby = u.userid
THEN 1 ELSE 0 END
) AS chapter,
SUM(
CASE WHEN c.translator = u.username
THEN 1 ELSE 0 END
) AS translator,
SUM(
CASE WHEN c.graphic = u.username
THEN 1 ELSE 0 END
) AS graphic
FROM user u
left JOIN manga m
ON m.sendby = u.userid
left JOIN chapter c
ON c.sendby = u.userid
where u.userid = '1'
但它返回的是不正确的:
漫画:16,章节:16,翻译:12,图形:8