0
我有以下查詢如何結合SELECT查詢和COUNT(*)查詢?
SELECT
c.cd,
c.c_id
FROM
f f
INNER JOIN s s
ON s.s_id = f.s_id
INNER JOIN c c
ON c.c_id = s.c_id
WHERE f.m_id = 2
AND f.deleted = 'no'
GROUP BY s.c_id
ORDER BY f.update_datetime DESC ;
它返回一個示例結果集:
c.cd c.c_id
moot 4
derp 5
我有基於上述結果集的c.c_id
另一個查詢其迭代對於在上述結果中的每個記錄設置:
SELECT COUNT(*) as totals FROM s
WHERE c_id =?
AND status='good';
回報7
時c_id=4
和返回20
當c_id=5
有什麼辦法可以結合這兩個查詢來形成這樣的結果集?
c.cd c.c_id totals
moot 4 7
derp 5 20