亚洲乱色熟女一区二区三区丝袜,天堂√中文最新版在线,亚洲精品乱码久久久久久蜜桃图片,香蕉久久久久久av成人,欧美丰满熟妇bbb久久久

LOGO OA教程 ERP教程 模切知識(shí)交流 PMS教程 CRM教程 開(kāi)發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

SQL 數(shù)據(jù)增加小計(jì)及合計(jì)行,求sql行合計(jì)列合計(jì)

Ccoffee
2015年12月24日 10:10 本文熱度 7740
表  
id 編號(hào)
time 時(shí)間
bm 部門(mén)
fy 費(fèi)用
數(shù)據(jù)
id time bm fy
1 2010-1-2 市場(chǎng)部 200
2 2010-1-5 行政部 500
4 2010-1-5 市場(chǎng)部 500
3 2010-3-5 行政部 400
5 2010-1-5 行政部 400
現(xiàn)在我要統(tǒng)計(jì)出結(jié)果
月份 市場(chǎng)部 行政部 合計(jì)
1月份 700 900 1600
。
。
。  
12月份 500 400 900
合計(jì) 1200 1300 2500
------回答---------
------回答(20分)---------
SQL code
if not object_id(''tb'') is null drop table tb Go Create table tb([id] int,[time] Datetime,[bm] nvarchar(3),[fy] int) Insert tb select 1,''2010-1-2'',N''市場(chǎng)部'',200 union all select 2,''2010-1-5'',N''行政部'',500 union all select 4,''2010-1-5'',N''市場(chǎng)部'',500 union all select 3,''2010-3-5'',N''行政部'',400 union all select 5,''2010-1-5'',N''行政部'',400 Go select ltrim(month(time))+''月份''月份, sum(case when bm=''市場(chǎng)部'' then fy else 0 end)市場(chǎng)部, sum(case when bm=''行政部'' then fy else 0 end)行政部, sum(fy)合計(jì) from tb group by ltrim(month(time))+''月份'' union all select N''合計(jì)'', sum(case when bm=''市場(chǎng)部'' then fy else 0 end), sum(case when bm=''行政部'' then fy else 0 end), sum(fy) from tb /* 月份 市場(chǎng)部 行政部 合計(jì) ---------------- ----------- ----------- ----------- 1月份 0 900 1600 3月份 0 400 400 合計(jì) 0 1300 2000 */
------回答(20分)---------
漏個(gè)合計(jì)
SQL code
--> 測(cè)試數(shù)據(jù): #tb if object_id(''tempdb.dbo.#tb'') is not null drop table #tb go create table #tb (id int,time datetime,bm varchar(6),fy int) insert into #tb select 1,''2010-1-2'',''市場(chǎng)部'',200 union all select 2,''2010-1-5'',''行政部'',500 union all select 4,''2010-1-5'',''市場(chǎng)部'',500 union all select 3,''2010-3-5'',''行政部'',400 union all select 5,''2010-1-5'',''行政部'',400 select [月份]=isnull(ltrim(number)+''月份'',''合計(jì)''), [行政部]=sum(case when bm=''行政部'' then fy else 0 end), [市場(chǎng)部]=sum(case when bm=''市場(chǎng)部'' then fy else 0 end), [合計(jì)]=sum(isnull(fy,0)) from #tb a right join master..spt_values s on month(time)=number where type=''p'' and number between 1 and 12 group by ltrim(number)+''月份'' with rollup order by cast(replace(replace(isnull(ltrim(number)+''月份'',''合計(jì)''),''合計(jì)'',''13月份''),''月份'','''') as int) 月份 行政部 市場(chǎng)部 合計(jì) ---------------- ----------- ----------- ----------- 1月份 900 700 1600 2月份 0 0 0 3月份 400 0 400 4月份 0 0 0 5月份 0 0 0 6月份 0 0 0 7月份 0 0 0 8月份 0 0 0 9月份 0 0 0 10月份 0 0 0 11月份 0 0 0 12月份 0 0 0 合計(jì) 1300 700 2000 (13 行受影響)

------回答---------

------回答(20分)---------

SQL code
if not object_id(''tb'') is null drop table tb Go Create table tb([id] int,[time] Datetime,[bm] nvarchar(3),[fy] int) Insert tb select 1,''2010-1-2'',N''市場(chǎng)部'',200 union all select 2,''2010-1-5'',N''行政部'',500 union all select 4,''2010-1-5'',N''市場(chǎng)部'',500 union all select 3,''2010-3-5'',N''行政部'',400 union all select 5,''2010-1-5'',N''行政部'',400 Go select ltrim(month(time))+''月份''月份, sum(case when bm=''市場(chǎng)部'' then fy else 0 end)市場(chǎng)部, sum(case when bm=''行政部'' then fy else 0 end)行政部, sum(fy)合計(jì) from tb group by ltrim(month(time))+''月份'' union all select N''合計(jì)'', sum(case when bm=''市場(chǎng)部'' then fy else 0 end), sum(case when bm=''行政部'' then fy else 0 end), sum(fy) from tb /* 月份 市場(chǎng)部 行政部 合計(jì) ---------------- ----------- ----------- ----------- 1月份 0 900 1600 3月份 0 400 400 合計(jì) 0 1300 2000 */
------回答(20分)---------


漏個(gè)合計(jì)
SQL code
--> 測(cè)試數(shù)據(jù): #tb if object_id(''tempdb.dbo.#tb'') is not null drop table #tb go create table #tb (id int,time datetime,bm varchar(6),fy int) insert into #tb select 1,''2010-1-2'',''市場(chǎng)部'',200 union all select 2,''2010-1-5'',''行政部'',500 union all select 4,''2010-1-5'',''市場(chǎng)部'',500 union all select 3,''2010-3-5'',''行政部'',400 union all select 5,''2010-1-5'',''行政部'',400 select [月份]=isnull(ltrim(number)+''月份'',''合計(jì)''), [行政部]=sum(case when bm=''行政部'' then fy else 0 end), [市場(chǎng)部]=sum(case when bm=''市場(chǎng)部'' then fy else 0 end), [合計(jì)]=sum(isnull(fy,0)) from #tb a right join master..spt_values s on month(time)=number where type=''p'' and number between 1 and 12 group by ltrim(number)+''月份'' with rollup order by cast(replace(replace(isnull(ltrim(number)+''月份'',''合計(jì)''),''合計(jì)'',''13月份''),''月份'','''') as int) 月份 行政部 市場(chǎng)部 合計(jì) ---------------- ----------- ----------- ----------- 1月份 900 700 1600 2月份 0 0 0 3月份 400 0 400 4月份 0 0 0 5月份 0 0 0 6月份 0 0 0 7月份 0 0 0 8月份 0 0 0 9月份 0 0 0 10月份 0 0 0 11月份 0 0 0 12月份 0 0 0 合計(jì) 1300 700 2000 (13 行受影響)

該文章在 2015/12/24 10:12:04 編輯過(guò)
關(guān)鍵字查詢(xún)
相關(guān)文章
正在查詢(xún)...
點(diǎn)晴ERP是一款針對(duì)中小制造業(yè)的專(zhuān)業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國(guó)內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對(duì)港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場(chǎng)、車(chē)隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場(chǎng)作業(yè)而開(kāi)發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類(lèi)企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉(cāng)儲(chǔ)管理系統(tǒng)提供了貨物產(chǎn)品管理,銷(xiāo)售管理,采購(gòu)管理,倉(cāng)儲(chǔ)管理,倉(cāng)庫(kù)管理,保質(zhì)期管理,貨位管理,庫(kù)位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號(hào)管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶(hù)的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved