日期:2014-05-16 浏览次数:20803 次
select 违规类型,
decode(to_char(违规时间,'MM'),'01',count(*)) as '1月',
decode(to_char(违规时间,'MM'),'02',count(*)) as '2月',
......
decode(to_char(违规时间,'MM'),'12',count(*)) as '12月'
from table
group by 违规类型
create table TMP_TEST
(
id NUMBER,
c_type VARCHAR2(20),
d_time DATE
);
insert into TMP_TEST (ID, C_TYPE, D_TIME) values (1, '违规类型1', to_date('01-05-2012', 'dd-mm-yyyy'));
insert into TMP_TEST (ID, C_TYPE, D_TIME) values (2, '违规类型1', to_date('17-05-2012', 'dd-mm-yyyy'));
insert into TMP_TEST (ID, C_TYPE, D_TIME) values (3, '违规类型1', to_date('01-06-2012', 'dd-mm-yyyy'));
insert into TMP_TEST (ID, C_TYPE, D_TIME) values (4, '违规类型1', to_date('01-08-2012', 'dd-mm-yyyy'));
insert into TMP_TEST (ID, C_TYPE, D_TIME) values (5, '违规类型2', to_date('01-05-2012', 'dd-mm-yyyy'));
insert into TMP_TEST (ID, C_TYPE, D_TIME) values (6, '违规类型2', to_date('01-06-2012', 'dd-mm-yyyy'));
insert into TMP_TEST (ID, C_TYPE, D_TIME) values (7, '违规类型2', to_date('01-08-2012', 'dd-mm-yyyy'));
commit;
select c_type,
count(decode(to_char(d_time, 'mm'), '01', 1)) "1月",
count(decode(to_char(d_time, 'mm'), '02', 1)) "2月",
count(decode(to_char(d_time, 'mm'), '03', 1)) "3月",
count(decode(to_char(d_time, 'mm'), '04', 1)) "4月",
count(decode(to_char(d_time, 'mm'), '05', 1)) "5月",
count(decode(to_char(d_time, 'mm'), '06', 1)) "6月"
from TMP_TEST
group by c_type;
select c_type,
count(decode(to_char(d_time, 'mm'), '01', 1,0)) "1月",
count(decode(to_char(d_time, 'mm'),&n