在' CALLS' table每个调用都有一个call_start,contact_id,operator_id等。
我想计算特定工作日每个客户端的tot调用,所以我提取工作日(从call_start中提取工作日),我得到0到6个结果。
我用一个案例来显示工作日(case when (extract(weekday from call_start)=1) then 'monday'
等等。
现在我输入count( client_id)
我得到2行2次通话,4行4次通话,而不是1行2次通话?
我在这里错过了一些愚蠢的东西吗?
我正在使用Firebird 1.5
答案 0 :(得分:0)
select
sum(case when extract(weekday from cast(call_start as date))=0 then 1 else 0 end) as qty_sun,
sum(case when extract(weekday from cast(call_start as date))=1 then 1 else 0 end) as qty_mon,
sum(case when extract(weekday from cast(call_start as date))=2 then 1 else 0 end) as qty_tue,
....