用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - sql代码库

转置

2014-12-03 作者: 苦瓜爱代码举报

[sql]代码库

select dd.STCD,
sum(CASE WHEN M='1' then MZ ELSE 0  END) AS '1月',
sum(CASE WHEN M='2' then MZ ELSE 0  END) AS '2月',
sum(CASE WHEN M='3' then MZ  ELSE 0 END) AS '3月',
sum(CASE WHEN M='4' then MZ  ELSE 0 END) AS '4月',
sum(CASE WHEN M='5' then MZ  ELSE 0 END) AS '5月',
sum(CASE WHEN M='6' then MZ  ELSE 0 END) AS '6月',
sum(CASE WHEN M='7' then MZ  ELSE 0 END) AS '7月',
sum(CASE WHEN M='8' then MZ  ELSE 0 END) AS '8月',
sum(CASE WHEN M='9' then MZ  ELSE 0 END) AS '9月',
sum(CASE WHEN M='10' then MZ  ELSE 0 END) AS '10月',
sum(CASE WHEN M='11' then MZ  ELSE 0 END) AS '11月',
sum(CASE WHEN M='12' then MZ  ELSE 0 END) AS '12月',
MAX(MZ) AS MZ
,(SELECT TOP 1 MAXZTM FROM AA_RIVER_EV AA WHERE STCD=dd.STCD AND MAXZ=MAX(dd.MZ) ORDER BY MAXZTM DESC)TM
from (SELECT STCD, MAX(MAXZ) AS MZ, Convert(int,SUBSTRING(YM,5,6)) AS M, MAXZTM AS TM
 FROM AA_RIVER_EV  GROUP BY STCD,YM, MAXZTM,MAXZ) dd  
 GROUP BY dd.STCD


--在修改语句中,单引号要用两个作转义字符。
 update dbo.Config_Expand_DataSource set content='select dd.STCD,sum(CASE WHEN M=''1'' then MZ ELSE 0  END) AS ''AM'',sum(CASE WHEN M=''2'' then MZ ELSE 0  END) AS ''BM'',sum(CASE WHEN M=''3'' then MZ  ELSE 0 END) AS ''CM'',sum(CASE WHEN M=''4'' then MZ  ELSE 0 END) AS ''DM'',sum(CASE WHEN M=''5'' then MZ  ELSE 0 END) AS ''EM'',sum(CASE WHEN M=''6'' then MZ  ELSE 0 END) AS ''FM'',sum(CASE WHEN M=''7'' then MZ  ELSE 0 END) AS ''GM'',sum(CASE WHEN M=''8'' then MZ  ELSE 0 END) AS ''HM'',sum(CASE WHEN M=''9'' then MZ  ELSE 0 END) AS ''IM'',sum(CASE WHEN M=''10'' then MZ  ELSE 0 END) AS ''JM'',sum(CASE WHEN M=''11'' then MZ  ELSE 0 END) AS ''KM'',sum(CASE WHEN M=''12'' then MZ  ELSE 0 END) AS ''LM'',MAX(MZ) AS MZ,(SELECT TOP 1 MAXZTM FROM AA_RIVER_EV AA WHERE STCD=dd.STCD AND MAXZ=MAX(dd.MZ) ORDER BY MAXZTM DESC)TM from (SELECT STCD, MAX(MAXZ) AS MZ, Convert(int,SUBSTRING(YM,5,6)) AS M, MAXZTM AS TM FROM AA_RIVER_EV GROUP BY STCD, YM, MAXZTM) dd GROUP BY dd.STCD'
  where DataSourceID=4


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...