能否请您帮我写一个查询,以从下面的查询中提取Daywise数据和总数据。
Select TCl.CircleCode Location,
COUNT(CASE
WHEN HostResponse=0 THEN 'Failure'
End) Failure,
Count(Case
WHEN HostResponse=1 THEN 'Success'
END) 'Success'
from [dbo].[TBL_DTL_HOST] Host Join [TBL_DTL_CALLACTIVITY_REALTIME_230818] TCL On
Host.CallID = TCL.CallID
Where HostMethod='Caller Validation'
and CallDateTime Between '2018-07-01 00:00:00' and '2018-07-24 23:59:59'
Group by TCl.CircleCode
答案 0 :(得分:1)
SELECT
TCl.CircleCode Location
, Count(CASE
WHEN HostResponse = 0
THEN 'Failure'
END) Failure
, Count(CASE
WHEN HostResponse = 1
THEN 'Success'
END) 'Success'
, Cast(CallDateTime AS DATE) CallDate
FROM
dbo.TBL_DTL_HOST Host
JOIN TBL_DTL_CALLACTIVITY_REALTIME_230818 TCL ON Host.CallID = TCL.CallID
WHERE HostMethod = 'Caller Validation'
AND CallDateTime BETWEEN '2018-07-01 00:00:00' AND '2018-07-24 23:59:59'
GROUP BY
Cast(CallDateTime AS DATE)
, TCl.CircleCode;
答案 1 :(得分:0)
基于对您的数据结构以及“按日数据”的含义的一些有根据的猜测,我建议您只需在CallDate
和Select
子句中添加一个Group By
计算列-像这样的东西:
Select
TCL.CircleCode As Location
, DateFromParts(Year(CallDateTime), Month(CallDateTime), Day(CallDateTime)) As CallDate
, Count(Case
When HostResponse = 0 Then 'Failure'
End
) As Failure
, Count(Case
When HostResponse = 1 Then 'Success'
End
) As Success
From dbo.TBL_DTL_HOST As Host
Join TBL_DTL_CALLACTIVITY_REALTIME_230818 As TCL
On Host.CallID = TCL.CallID
Where
HostMethod = 'Caller Validation'
And CallDateTime Between '2018-07-01 00:00:00'
And '2018-07-24 23:59:59'
Group By
DateFromParts(Year(CallDateTime), Month(CallDateTime), Day(CallDateTime))
, TCL.CircleCode
如果这不适用于您,那么您需要向问题中添加示例数据和所需的输出。