62,271
社区成员
发帖
与我相关
我的任务
分享
select *
,(case comment when 'private' then point end ) 'private'
,(case comment when 'public' then point end ) 'public'
,(case comment when 'qunfa' then point end ) 'qunfa' from #1
where comment like ''
create table #1
(
[ID] [int] IDENTITY(1,1) NOT NULL,
[createDate] [date] NULL,
[name] [nvarchar](50) NULL,
[comment] [nvarchar](50) NULL,
[point] [int] NULL
)
go
insert into #1 (createdate ,[name],comment,point) values ('2010-05-06','a','private',50)
insert into #1 (createdate ,[name],comment,point) values ('2010-05-06','a','public',30)
insert into #1 (createdate ,[name],comment,point) values ('2010-05-06','b','public',40)
insert into #1 (createdate ,[name],comment,point) values ('2010-05-07','a','qunfa',100)
select createdate,[name],
cast(isnull([private],0) as nvarchar) + '/' + cast(isnull([public],0) as nvarchar) + '/' + cast(isnull([qunfa],0) as nvarchar)
from (
select createdate,[name],
SUM([private]) 'private',SUM([public]) 'public' ,SUM([qunfa]) 'qunfa'
from (select *
,(case comment when 'private' then point end ) 'private'
,(case comment when 'public' then point end ) 'public'
,(case comment when 'qunfa' then point end ) 'qunfa' from #1) a
group by createdate,[name]) b
drop table #1