pivot query with dynamic in clause
I'm working on a pivot query which tracks by time (by minute). I need it to report on the last 12 or 24 hours or several days. But, the problem is I can't determine how to build the "in" clause. Here it is:
with pivot_data as (select 'prod' as src, to_char(datetime,'YYYY-MM-DD HH24:MI') as time, sum(1) as cnt
from prod
where datetime > sysdate - .5
group by to_char(datetime,'YYYY-MM-DD HH24:MI')
union all
select 'test' as src, to_char(datetime,'YYYY-MM-DD HH24:MI') as time, sum(1) as cnt
from test
where datetime > sysdate - .5
group by to_char(datetime,'YYYY-MM-DD HH24:MI'))
select *
from pivot_data
pivot (sum(cnt)
for time in ('2015-08-27 23:30','2015-08-27 23:31','2015-08-27 23:32','2015-08-27 23:33', . . . )
Tagged:
0