这是mysql查询
SELECT CallDate,SUM(Hour0) AS FailedCalls FROM call_status WHERE CallDate='2012-09-14' AND CallStatusId NOT IN (42,52)
UNION
SELECT CallDate,SUM(Hour0) AS SuccessCalls FROM call_status WHERE CallDate='2012-09-14' AND CallStatusId IN (42,52);
这是输出
抱歉图片太小了。如您所见,我从上面的查询中选择了失败的呼叫,并使用第二个查询选择了 SuccessCalls。但我想要的是 CallDate、FailedCalls、SuccessCalls 在一行中。
更新: 这是正确的查询:
SELECT CallDate,
SUM(CASE WHEN (CallStatusId NOT IN(42,52)) THEN Hour0
ELSE 0
END) AS FailedCalls,
SUM(CASE WHEN (CallStatusId IN (42,52)) THEN Hour0
ELSE 0
END) AS SuccessCalls
FROM call_status
WHERE CallDate='2012-09-14';