SQL 之Group by with Rollup效果(2)_SQL SERVER数据库_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

SQL 之Group by with Rollup效果(2)

作者:黑客防线网安SQL维护基地 来源:黑客防线网安SQL维护基地 浏览次数:0

本篇关键词:效果nullsect
黑客防线网安网讯:  -- 对其中一个进行转换标题的增强效果 select dept , sect , line ,   ( case  when (title_code is null) and ( line is not null) then ’total ( by Line ) : ’ else title_code en...

  -- 对其中一个进行转换标题的增强效果
select dept , sect , line , 
 ( case  when (title_code is null) and ( line is not null) then ’total ( by Line ) : ’ else title_code end )  as title_code, 
 sum(headcount) as Headcounts
 from #tmpA
 group by dept , sect , line , title_code with rollup

-- 对所有的进行处理后的结果
select  
 ( case  when (dept is null) then ’Grant total  : ’ else isNull(dept,’’)  end )  as sect, 
 ( case  when (sect is null) and ( dept is not null) then ’total ( by Dept ) : ’ else IsNull(sect,’’) end )  as sect, 
 ( case  when (line is null) and ( sect is not null) then ’total ( by Sect ) : ’ else IsNull(line,’’) end )  as line, 
 ( case  when (title_code is null) and ( line is not null) then ’total ( by Line ) : ’ else isNull(title_code,’’) end )  as title_code, 
 sum(headcount) as Headcounts
 from #tmpA
 group by dept , sect , line , title_code with rollup

-- 对所有的进行处理后的结果
select  
 ( case  when (dept is null) then ’Grand total  : ’ else isNull(dept,’’)  end )  as sect, 
 ( case  when (sect is null) and ( dept is not null) then ’Total ( by Dept  : ’ + dept + ’) : ’ else IsNull(sect,’’) end )  as sect, 
 ( case  when (line is null) and ( sect is not null) then ’Total ( by Sect : ’ + Sect + ’ ) : ’ else IsNull(line,’’) end )  as line, 
 ( case  when (title_code is null) and ( line is not null) then ’小计 ( 按组别  : ’ + line + ’) : ’ else isNull(title_code,’’) end )  as title_code, 
 sum(headcount) as Headcounts
 from #tmpA
 group by dept , sect , line , title_code with rollup

select  
 ( case  when (dept is null) then ’Grant total  : ’ else isNull(dept,’’)  end )  as sect, 
 ( case  when (sect is null) and ( dept is not null) then ’total ( by Dept ) : ’ else IsNull(sect,’’) end )  as sect,

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-11495-1.html
网站维护教程更新时间:2012-03-21 03:21:57  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer