2013-10-24 50 views
0

我有一個持續時間列,其中包含以秒爲單位的值。現在根據我的需要,我必須將其顯示到SEC_TO_TIME中。mysql中的SEC_TO_TIME函數正在計算組中的一個條件:

SELECT wwid, 
round(SUM(CASE toc WHEN 'LOCAL' THEN callcost ELSE 0 END),2) AS LOCALPRICE, 
round(SUM(CASE toc WHEN 'STD' THEN callcost ELSE 0 END),2) AS STDPRICE, 
round(SUM(CASE toc WHEN 'ISD' THEN callcost ELSE 0 END),2) AS ISDPRICE, 
round(SUM(CASE toc WHEN 'INCOMING' THEN callcost ELSE 0 END),2) AS INCOMINGPRICE, 
count(case when toc = 'LOCAL' then 1 end) as LOCALCALLS, 
count(case when toc = 'STD' then 1 end) as STDCALLS, 
count(case when toc = 'ISD' then 1 end) as ISDCALLS, 
count(case when toc = 'INCOMING' then 1 end) as INCOMCALLS, 
SEC_TO_TIME(CASE toc WHEN 'LOCAL' THEN sum(duration) ELSE 0 END)AS LOCALDUR, 
SEC_TO_TIME(CASE toc WHEN 'STD' THEN sum(duration) ELSE 0 END)AS STDDUR, 
SEC_TO_TIME(CASE toc WHEN 'ISD' THEN sum(duration) ELSE 0 END)AS ISDDUR, 
SEC_TO_TIME(CASE toc WHEN 'INCOMING' THEN sum(duration) ELSE 0 END)AS INCOMDUR, 
count(destination) as TOTALCALLS, 
SEC_TO_TIME(sum(duration))as TOTALDUR, 
round(sum(callcost),2)as TOTALPRICE 
FROM processeddata_table 
WHERE calldate between '2010-10-01' and '2013-10-01' 
group by wwid 
LIMIT 0 , 50 

這裏每次我們需要得到SEC_TO_TIME的形式,但對於每一個WWID持續時間WWID來了只有一個CALLTYPE讓它是本地,性病,政府新聞處等wheras它的存在對別人也

任何幫助將高度讚賞..提前

謝謝..

+0

這似乎是關於單列值。爲什麼發佈那麼大(未格式化)的查詢? –

+0

@juergend對不起先生我是新手在這個論壇不知道發佈查詢..請指導.. – vikas

+0

在問題編輯器中使用代碼按鈕'{}'來格式化代碼。標記代碼並單擊按鈕。 –

回答

0

取而代之的是...

SEC_TO_TIME(CASE toc WHEN 'STD' THEN sum(duration) ELSE 0 END)AS STDDUR 

...你可能是打算是這樣的......

SEC_TO_TIME(SUM(CASE toc WHEN 'STD' THEN duration ELSE 0 END)) AS STDDUR 

的SUM()聚合函數需要申請,無論這種情況下,各行的小組賽。這需要在具有類似表達式的所有列上進行更改。