2017-02-04 47 views
0

我需要時間智者的銷售報告在MySQL中,我得到這樣如何獲得時間明智記錄在MySQL

Time Amount 
19:00:00 2 
20:00:00 5 
21:00:00 0 
22:00:00 0 
23:00:00 14 

報告,但我需要一個像

Time Amount 
19:00:00 2 
20:00:00 5 
21:00:00 5 
22:00:00 5 
23:00:00 14 

金額的總和這是我的查詢

SELECT concat(MID(date_of_call, 12, 2),':00:00') TimeIntervel,COUNT(*) TotalEntries,date_format(date_of_call,'%d/%m/%Y') FROM ICC_MM_setup_suply 
WHERE DATE_FORMAT(date_of_call,'%d/%m/%Y')='31/01/2017' 
GROUP BY concat(MID(date_of_call, 12, 2),':00:00') 
+0

如果你能和'WHERE date_of_call ='2017-01-31''一起生活,它的​​潛力會更快 – Strawberry

+0

爲什麼數據集有零? (這很令人困惑,因爲結果與查詢不符) – Strawberry

回答

0

您可以使用用戶變量:

set @lastval := 0;  
select 
    time, 
    @lastval := if(Amount = 0, @lastval, Amount) Amount 
from t 
order by time;