我有三個表是這樣的:在一個查詢中多計
漫畫
| id | sendby
------------------
| 1 | 1
| 2 | 1
| 3 | 1
| 4 | 1
chaprer
| 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
你想要的結果是什麼? – 2012-08-12 13:17:34
這是:漫畫:4,章節:4,翻譯:3,圖形:2 – kamal 2012-08-12 13:19:05