日期:2014-05-17 浏览次数:20692 次
drop table tabletest
create table tableTest
(
dept varchar(20),
Class varchar(20),
CategoryA varchar(20),
CategoryB varchar(20),
CreateDate datetime
)
insert into tableTest values ('部门1','1','是','',getdate())
insert into tableTest values ('部门1','2','是','',getdate())
insert into tableTest values ('部门1','2','','是',getdate())
insert into tableTest values ('部门1','1','是','',getdate())
insert into tableTest values ('部门2','1','是','',getdate())
insert into tableTest values ('部门2','2','','是',getdate())
insert into tableTest values ('部门2','1','是','',getdate())
insert into tableTest values ('部门2','1','是','',getdate())
select * from tabletest
select dept,class,count(class) as 级别次数 from tabletest
--where dept=''
group by dept,class
order by dept
/*
部门1 1 2
部门1 2 2
部门2 1 3
部门2 2 1
*/
drop table tabletest
create table tableTest
(
dept varchar(20),
Class varchar(20),
CategoryA varchar(20),
CategoryB varchar(20),
CreateDate datetime
)
insert into tableTest values&nb