跳过行的打印

时间:2016-01-01 22:52:53

标签: sql oracle oracle11g

我想在此表中显示图表中的数据:

CREATE TABLE EVENT(
  ID INTEGER NOT NULL,
  SOURCE VARCHAR2(50 ),
  TYPE VARCHAR2(50 ),
  EVENT_DATE DATE,
  DESCRIPTION VARCHAR2(100 )
)
/

我使用这个SQL查询:

select event_date, sum(case when type = 'Error' then 1 else 0 end) as Error,
sum(case when type = 'Warn' then 1 else 0 end) as Warn, sum(case when type = 'Info' then 1 else 0 end) as Info, 
sum(case when type = 'Critical' then 1 else 0 end) as Critical 
from event e where event_date >= trunc(sysdate) - 15
group by event_date 
order by event_date

我得到了这个结果:

01-JAN-16   0   0   0   0
01-JAN-16   0   0   0   0
02-JAN-16   20  0   10  0
03-JAN-16   0   0   0   0

如何跳过我有0个活动的日子?

1 个答案:

答案 0 :(得分:2)

只需在HAVING COUNT(CASE WHEN type IN ('Info', 'Warn', 'Error', 'Critical') THEN 1 END) > 0子句后添加GROUP BY

select event_date, sum(case when type = 'Error' then 1 else 0 end) as Error,
sum(case when type = 'Warn' then 1 else 0 end) as Warn, sum(case when type = 'Info' then 1 else 0 end) as Info, 
sum(case when type = 'Critical' then 1 else 0 end) as Critical 
from event e where event_date >= trunc(sysdate) - 15
group by event_date
having count(case when type IN ('Info', 'Warn', 'Error', 'Critical') then 1 end) > 0
order by event_date