這篇文章主要介紹“mssql中CASE,GROUP BY語句的用法”,在日常操作中,相信很多人在mssql中CASE,GROUP BY語句的用法問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”mssql中CASE,GROUP BY語句的用法”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
復(fù)制代碼 代碼如下:
--create database dbTemp use dbTemp create table test ( Pid int identity(1,1) not null primary key, Years datetime, IsFirstSixMonths int default(0), --0表示上半年1表示下半年-- TotalCome int ) insert test select '2007-1-1',0,50 union select '2007-3-1',0,60 union select '2007-12-1',1,80 union select '2008-1-1',0,100 union select '2008-12-1',1,100 select * from test select convert(char(4),Years,120) as 'year', IsFirstSixMonths=case when IsFirstSixMonths=0 then '上半年' when IsFirstSixMonths=1 then '下半年' END , sum(totalcome) as 'sum' from test group by IsFirstSixMonths,convert(char(4),Years,120) select convert(char(4),Years,120) as 'year', IsFirstSixMonths=case when IsFirstSixMonths=0 then '上半年' ELSE '下半年' END , sum(totalcome) as 'sum' from test group by IsFirstSixMonths,convert(char(4),Years,120) --DROP DATABASE dbtemp
結(jié)果如下:
2007 上半年 110 2007 下半年 80 2008 上半年 100 2008 下半年 100
到此,關(guān)于“mssql中CASE,GROUP BY語句的用法”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
本文標(biāo)題:mssql中CASE,GROUPBY語句的用法-創(chuàng)新互聯(lián)
鏈接URL:http://www.chinadenli.net/article30/doidpo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、搜索引擎優(yōu)化、用戶體驗(yàn)、自適應(yīng)網(wǎng)站、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容