我有SQL查詢得到6列的表從聚合函數where條件句
mytable:
TotalNumberOfRecords
TotalDurationOfCalls
AvgdurationPer
TotalCallednumbers
TotalCallednumbers
Ratiocalledtoallcalls
這些列導致的聚集功能。但每個人都有不同的條件句子以便從表中選擇。
我的查詢是這樣的:
select ID,
count(*) as TotalNumberOfRecords,
sum (isnull(cast(duration as int),0)) {where condition1} as TotalDurationOfCalls ,
AVG(isnull(cast(duration as int),0)){where condition2} as AvgdurationPer,
count(distinct IDS) {where condition3} as TotalCallednumbers ,
count(distinct CGI) {where condition4} as TotalOfLocations,
cast(count(distinct IDS) as float)/cast(count(*) as float) {where condition5} as Ratiocalledtoallcalls
from Mytable
group by ID
現在,我的問題是,我怎麼能在一個查詢執行此查詢來獲取一個表?
你使用MySQL,SQL Server 2008或SQL Server 2012中:您可以通過製作
case
表達參數的聚集功能做到這一點?你已經標記了所有三個。另外,我不清楚你在問什麼。 –基於大量的證據,我將MySQL標記更改爲sql。 –