select to_char(SIGNDATE,'yyyy-MM-dd HH24:mi') ,count(*) from (
SELECT * FROM (select ID,CODE,SIGNDATE FROM table1 WHERE SIGNDATE >= TO_DATE('2017-04-01 00:00:00','yyyy-MM-dd HH24:mi:ss')
AND SIGNDATE <= TO_DATE('2017-04-30 23:59:59','yyyy-MM-dd HH24:mi:ss') AND DELETED=0 AND ISPRINT=1
UNION ALL
select ID,CODE,SIGNDATE FROM table2 WHERE SIGNDATE >= TO_DATE('2017-04-01 00:00:00','yyyy-MM-dd HH24:mi:ss')
AND SIGNDATE <= TO_DATE('2017-04-30 23:59:59','yyyy-MM-dd HH24:mi:ss') AND DELETED=0 AND ISPRINT=1
UNION ALL
select ID,CODE,SIGNDATE FROM table3 WHERE SIGNDATE >= TO_DATE('2017-04-01 00:00:00','yyyy-MM-dd HH24:mi:ss')
AND SIGNDATE <= TO_DATE('2017-04-30 23:59:59','yyyy-MM-dd HH24:mi:ss') AND DELETED=0 AND ISPRINT=1
UNION ALL
select ID,CODE,SIGNDATE FROM table4 WHERE SIGNDATE >= TO_DATE('2017-04-01 00:00:00','yyyy-MM-dd HH24:mi:ss')
AND SIGNDATE <= TO_DATE('2017-04-30 23:59:59','yyyy-MM-dd HH24:mi:ss') AND DELETED=0 AND ISPRINT=1 )
WHERE SIGNDATE >= TO_DATE('2017-04-01 00:00:00','yyyy-MM-dd HH24:mi:ss')
) group by to_char(SIGNDATE,'yyyy-MM-dd HH24:mi')
order by to_char(SIGNDATE,'yyyy-MM-dd HH24:mi');
转载于:https://www.cnblogs.com/xiaoxiao0314/p/6774177.html