是这样吗:
--drop table testcreate table test(姓名 varchar(10), 年龄 int, 单位代码 varchar(10), 单位名 varchar(20))insert into test
select 'a', 20, '1000', '事业' union all
select 'a', 20, '1000', '事业' union all
select 'b', 22, '1001', '机关' union all
select 'b', 22, '1001', '机关' union all
select 'c', 19, '1002', '参公'
goselect COUNT(*) as 个数,单位名
from test
where 单位代码 in ('1000','1001')
group by 单位名
/*
个数 单位名
2 机关
2 事业
*/
是这样吗:
--drop table testcreate table test(姓名 varchar(10), 年龄 int, 单位代码 varchar(10), 单位名 varchar(20))insert into test
select 'a', 20, '1000', '事业' union all
select 'a', 20, '1000', '事业' union all
select 'b', 22, '1001', '机关' union all
select 'b', 22, '1001', '机关' union all
select 'c', 19, '1002', '参公'
goselect COUNT(*) as 个数,单位名
from test
where 单位代码 in ('1000','1001')
group by 单位名
/*
个数 单位名
2 机关
2 事业
*/谢谢