我的數據庫中有3行(未列出的所有列):添加COUNT(和限定),以SQL語句
**uFirst** | **uApp**
Dave | approved
John | declined
Jane | no
這個SQL工作,並顯示所有行:
SELECT u.uID, u.uManT, u.uFirst AS 'NomFN', m.uFirst AS 'ManFN', u.uLast AS 'NomLN', m.uLast AS 'ManLN', u.uNomd, u.uApp, u.uApp, u.uAppd, u.uRep, u.uRepd, u.uManT, u.uStatus, u.uManR
FROM users AS u LEFT OUTER JOIN users AS m
ON u.uManT = m.uID
WHERE u.uManR = " . $luID . "
AND u.uStatus = 'Physician'
ORDER BY u.uLast ASC";
當我嘗試添加COUNT,只顯示1行(經批准的):
SELECT COUNT(CASE WHEN u.uApp = 'approved' THEN 1 END) AS Approved,
COUNT(CASE WHEN u.uApp = 'declined' THEN 1 END) AS Declined,
u.uID, u.uManT, u.uFirst AS 'NomFN', m.uFirst AS 'ManFN', u.uLast AS 'NomLN', m.uLast AS 'ManLN', u.uNomd, u.uApp, u.uApp, u.uAppd, u.uRep, u.uRepd, u.uManT, u.uStatus, u.uManR
FROM users AS u LEFT OUTER JOIN users AS m
ON u.uManT = m.uID
WHERE u.uManR = " . $luID . "
AND u.uStatus = 'Physician'
ORDER BY u.uLast ASC";
我想顯示所有的行,數的計數的用戶被批准。我究竟做錯了什麼?
您的意思是用SUM? – Paulpro 2012-03-09 14:32:36
分享SHOW CREATE TABLE用戶 – rkosegi 2012-03-09 14:33:01