2012-05-16 64 views
1

我的SQL表達式可以正常顯示幾個月的結果,今年也可以。但是一年之後,我知道它會包含今年的結果。如何僅顯示當年的結果?SQL顯示幾個月的結果 - 如何僅顯示當前年份?

select case month(timestamp_iso(STATUSDATE)) 
     when 1 then 'January' 
     when 2 then 'February' 
     when 3 then 'March' 
     when 4 then 'April' 
     when 5 then 'May' 
     when 6 then 'Jun' 
     when 7 then 'July' 
     when 8 then 'August' 
     when 9 then 'September' 
     when 10 then 'October' 
     when 11 then 'November' 
     when 12 then 'December' 
    end as Month, 

    count (case when service='ADSL' then 1 end) as ADSL, 
    count (*) as ALL 

from INCIDENT 
group by month(timestamp_iso(STATUSDATE)) 

感謝

回答

3

添加where條款到最後:

where year(STATUSDATE) = year(current_timestamp) 
2

只需添加一個where條款!

你也可以使用monthname讓你在的情況下做什麼:

select MONTHNAME(timestamp_iso(STATUSDATE)) as Month, 
    count (case when service='ADSL' then 1 end) as ADSL, 
    count (*) as ALL 

from INCIDENT 
where year(STATUSDATE) = year(current_timestamp) 
group by month(timestamp_iso(STATUSDATE)) 

欲瞭解更多信息,請THISTHIS

相關問題