34,576
社区成员
发帖
与我相关
我的任务
分享
怪了,2008-01-10 17:27:34 怎么跑 2008-01-10 17:27:39后面去了
declare @a table (名称 varchar(50),推荐单位 varchar(50),项目经理 varchar(10))
insert into @a select '分包商1','一分局','张山'
insert into @a select '分包商1','二分局','李四'
insert into @a select '分包商1','一分局','王二'
insert into @a select '分包商2','一分局','张三'
select 名称 ,
(select count(distinct 推荐单位) from @a where 名称 = a.名称 ) as '推荐单位数量',
项目经理
from @a a
select 名称 ,
(select count(distinct 推荐单位) from [table] where 名称 = a.名称 ) as '推荐单位数量',
项目经理
from [table] a
select 分包商名称,
推荐单位数量 = (select count(*) from tb where 分包商名称 = t.分包商名称),
项目经理
from tb t
declare @t table(分包商名称 varchar(10),推荐单位 varchar(10),项目经理 varchar(10))
insert @t select
'分包商1','一分局','张山' union select
'分包商1','二分局','李四' union select
'分包商1','一分局','王二' union select
'分包商2','一分局','张三'
select 分包商名称 ,
[推荐单位数量]=(select count(distinct 推荐单位) from @t where 分包商名称 = a.分包商名称 ),
项目经理
from @t a
/*
分包商名称 推荐单位数量 项目经理
---------- ----------- ----------
分包商1 2 李四
分包商1 2 王二
分包商1 2 张山
分包商2 1 张三
(所影响的行数为 4 行)
*/
select 分包商名称 ,
[推荐单位数量]=(select count(1) from tablename where 分包商名称 = a.分包商名称 ),
项目经理
from tablename a