请教
declare @table table(
ID int identity primary key,
Name varchar(50),
rq datetime ,
Deptno varchar(10),
Deptname varchar(20)
)
insert into @table
select '张三','2010-1-1','A','办公室' union all
select '李四','2010-2-1','A01','行政' union all
select '五王','2010-1-1','B','车间' union all
select '陈六','2010-2-1','B01','车间一' union all
select '某某','2010-3-1','B02','车间二'
SELECT * FROM @table
GO
--显示的结果为:
--大部门 部门名称 人数
--A 办公室 2
--B 车间 3
如何能实现显示结果,O(∩_∩)O谢谢 --------------------编程问答-------------------- declare @table table
(
ID int identity primary key,
Name varchar(50),
rq datetime ,
Deptno varchar(10),
Deptname varchar(20)
)
insert into @table
select '张三','2010-1-1','A','办公室' union all
select '李四','2010-2-1','A01','行政' union all
select '五王','2010-1-1','B','车间' union all
select '陈六','2010-2-1','B01','车间一' union all
select '某某','2010-3-1','B02','车间二'
SELECT
A.Deptno as '大部门'
,A.Deptname as '部门名称'
,(Select Count(*) FROM @table where Deptno like A.Deptno+'%' ) as '人数'
FROM @table A WHERE LEN(A.Deptno)=1
GO --------------------编程问答-------------------- select a.deptno as '大部门',case a.deptno when A then '办公室' else '车间' end as '部门名称',(select count(*) from @table where deptno like a.deptno+'%') as '人数' from @table a where len(a.deptno)=1
go
补充:.NET技术 , C#