亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

sql材料分級(jí)統(tǒng)計(jì)及匯總案例參考

系統(tǒng) 1956 0

--第一步:根據(jù)系統(tǒng)編號(hào)、列、單價(jià)分組求和

select CLBH,DJ,sum(SL) as SL,sum(JE) as JE,Lie

??????????????????????????? into #TempSZCMX

?from #ShouZhiCunMingXi group by Lie, CLBH , DJ order by Lie,CLBH

?

?--第二步:列轉(zhuǎn)行,分組求和

?insert into #TempLastResults

SELECT YJ,EJ,

???????? MoJi=(CASE WHEN grouping(YJ) = 1 THEN '0'?

??????????????????????????? WHEN grouping(EJ) = 1 THEN [YJ]

??????????????????????????? when grouping(MoJi)=1 then [EJ] else MoJi END),

? DJ,

sum(SYSL) SYSL,SUM(SYJE) SYJE,SUM(BYSL) BYSL,SUM(BYJE) BYJE,

SUM(CKSL) CKSL,SUM(CKJE) CKJE,SUM(RKSL) RKSL,SUM(RKJE) RKJE

--into #TempLastResults

from

(

?

select CaiLiaoXinxi_1.SJ AS YJ,CaiLiaoXinxi_1.BH AS EJ,CaiLiaoXinxi.BH AS MoJi,DJ,

sum(case Lie when '上月' then SL else 0 end) as 'SYSL',

??????????????????????????? sum(case Lie when '上月' then JE else 0 end) as 'SYJE',

??????????????????????????? sum(case Lie when '本月' then SL else 0 end) as 'BYSL',

??????????????????????????? sum(case Lie when '本月' then JE else 0 end) as 'BYJE',

??????????????????????????? sum(case Lie when '出庫' then SL else 0 end) as 'CKSL',

??????????????????????????? sum(case Lie when '出庫' then JE else 0 end) as 'CKJE',

??????????????????????????? sum(case Lie when '入庫' then SL else 0 end) as 'RKSL',

??????????????????????????? sum(case Lie when '入庫' then JE else 0 end) as 'RKJE'

??????????????????????????? from #TempSZCMX inner join CaiLiaoXinxi ON #TempSZCMX.CLBH =CaiLiaoXinxi.XTBH

??????????????????????????? INNER JOIN CaiLiaoXinxi? CaiLiaoXinxi_1 ON CaiLiaoXinxi.SJ=CaiLiaoXinxi_1.BH

??????????????????????????? GROUP BY CaiLiaoXinxi.BH ,CaiLiaoXinxi_1.BH,CaiLiaoXinxi_1.SJ,DJ

??????????????????????????? ) as MingXi

??????????????????????????? group by YJ,EJ,MoJi,DJ with rollup? having grouping(MoJi) =1 union all???????

select CaiLiaoXinxi_1.SJ AS YJ,CaiLiaoXinxi_1.BH AS EJ,CaiLiaoXinxi.BH AS MoJi,DJ,

sum(case Lie when '上月' then SL else 0 end) as 'SYSL',

??????????????????????????? sum(case Lie when '上月' then JE else 0 end) as 'SYJE',

??????????????????????????? sum(case Lie when '本月' then SL else 0 end) as 'BYSL',

??????????????????????????? sum(case Lie when '本月' then JE else 0 end) as 'BYJE',

??????????????????????????? sum(case Lie when '出庫' then SL else 0 end) as 'CKSL',

??????????????????????????? sum(case Lie when '出庫' then JE else 0 end) as 'CKJE',

??????????????????????????? sum(case Lie when '入庫' then SL else 0 end) as 'RKSL',

??????????????????????????? sum(case Lie when '入庫' then JE else 0 end) as 'RKJE'

??????????????????????????? --into #TempLastResults

??????????????????????????? from #TempSZCMX inner join CaiLiaoXinxi ON #TempSZCMX.CLBH =CaiLiaoXinxi.XTBH

??????????????????????????? INNER JOIN CaiLiaoXinxi? CaiLiaoXinxi_1 ON CaiLiaoXinxi.SJ=CaiLiaoXinxi_1.BH

??????????????????????????? GROUP BY CaiLiaoXinxi.BH ,CaiLiaoXinxi_1.BH,CaiLiaoXinxi_1.SJ,DJ ????????????????????

--第三步:求最終結(jié)果

select MC,GG,DW,DJ,SYSL,SYJE,RKSL,RKJE,CKSL,CKJE,BYSL,BYJE

from #TempLastResults inner join

(

?SELECT '0' AS BH,'全部材料總計(jì)' AS MC,'' AS GG,'' AS DW

?UNION ALL

?SELECT BH,(MC+'? 合計(jì)') AS MC,GG,DW FROM CaiLiaoXinxi WHERE SJ='0' and MJ=0

?UNION ALL SELECT BH,(MC+'? 小計(jì)') AS MC,GG,DW FROM CaiLiaoXinxi WHERE SJ<>'0' AND MJ=0

?UNION ALL SELECT BH, MC,GG,DW FROM CaiLiaoXinxi WHERE MJ=1

?) AS B on B.BH=#TempLastResults.MoJi and B.BH like @LeiBie order by B.BH

sql材料分級(jí)統(tǒng)計(jì)及匯總案例參考


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 九九久久视频 | 伊人99在线 | 台湾成人性视频免费播放 | 在线观看亚洲成人 | 波多野结衣一区二区 三区 波多野结衣一区二区三区 波多野结衣一区二区三区高清在线 | 国产免费观看a大片的网站 国产免费精彩视频 | 国产精品女仆装在线播放 | aaa级大片| 久久久久久久国产免费看 | 五月天婷婷在线播放 | 国语偷拍视频在线观看 | 欧美精品香蕉在线观看网 | 高清国产一区二区三区 | 久久精品网址 | 午夜a一级毛片一.成 | 在线看片不卡 | 在线综合 亚洲 欧美中文字幕 | 天天色综合色 | m3u8久久国产精品影院 | se成人 | 午夜精品久久久久久久99热 | 亚洲另类精品综合 | 欧美成人精品一级高清片 | 中文字幕一区二区三区精品 | 91成人免费在线视频 | 久久精品伊人 | 久久国产精品免费一区二区三区 | 91年精品国产福利线观看久久 | 天天摸夜夜操 | 亚洲国产高清一区二区三区 | 亚洲日产| 国产精品视频免费在线观看 | 久久国产精品一区 | 波多野结衣一区2区3区 | 久久天天躁夜夜躁狠狠躁2015 | 国产首页精品 | 在线播放波多野结衣 | 91视频大全| 精品无人乱码区1区2区3区 | 99伊人精品 | 亚洲一区在线免费 |