你完全过度了解查询...在内部预先求和,然后再在外面求和。此外,我知道您不是DBA,但如果您正在进行聚合,则通常需要按其分组的条件。在此处显示的情况下,您将获得所有实体ID的调用总和。因此,您必须拥有任何非聚合的组。但是,如果您关心的是Grand total而不考虑entity_ID,那么您可以跳过该组,但也不包括实际的实体ID ...
如果您希望包含显示每个特定实体ID的实际时间...
SELECT
entity_id,
sum(answered_day_call_time) as day_call_time,
count(*) number_of_calls
FROM
XCDRDNCSum201108
where
(day_of_the_month >= 10 AND day_of_the_month<=24)
and LPAD(core_range,4,"0")="0987"
and LPAD(subrange,3,"0")="654"
and SUBSTR(LPAD(core_number,7,"0"),4,7)="3210"
group by
entity_id这会导致像(虚构数据)
Entity_ID Day_Call_Time Number_Of_Calls
1 10 3
2 45 4
3 27 2如果您关心的是总呼叫时间
SELECT
sum(answered_day_call_time) as day_call_time,
count(*) number_of_calls
FROM
XCDRDNCSum201108
where
(day_of_the_month >= 10 AND day_of_the_month<=24)
and LPAD(core_range,4,"0")="0987"
and LPAD(subrange,3,"0")="654"
and SUBSTR(LPAD(core_number,7,"0"),4,7)="3210"这会导致像(虚构数据)
Day_Call_Time Number_Of_Calls
82 9