最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

sql動(dòng)態(tài)行轉(zhuǎn)列的兩種方法

 更新時(shí)間:2013年04月15日 10:12:25   作者:  
sql動(dòng)態(tài)行轉(zhuǎn)列的兩種方法,需要的朋友可以參考一下

第一種方法:

復(fù)制代碼 代碼如下:

select *from ( select Url,case  when  Month=01 then  '1月' when  Month=02 then '2月' when  Month=03 then  '3月' when  Month=04 then '4月' when  Month=05 then  '5月' when  Month=06 then '6月' when  Month=07 then  '7月' when  Month=08 then '8月' when  Month=09 then  '9月' when  Month=10 then ' 10月' when  Month=11 then  '11月' when  Month=12 then ' 12月'

 end  month,Quality from  (

select Url,DATENAME(M,AuditingTime)Month,SUM(Quality) Quality from  tb_order as a left join  tb_WebSiteInfo as b on a.WebSiteInfoID=b.ID left join  tb_OrderList as c on c.OrderID=a.ID where AuditingTime>'2013-01-01' and b.ID>0 and Auditing=2

group by Url,DATENAME(M,AuditingTime) )as h ) as hh

 pivot ( sum(Quality) for month in([1月],[2月],[3月],[4月],[5月],[6月],[7月],[8月],[9月],[10月],[11月],[12月])) as a


第二種方法:
復(fù)制代碼 代碼如下:

declare @sql varchar(8000)

select @sql = isnull(@sql + ',' , '') + '['+CONVERT(varchar(7),AuditingTime,20)+']'

from  tb_order as a left join  tb_WebSiteInfo as b on a.WebSiteInfoID=b.ID left join  tb_OrderList as c on c.OrderID=a.ID where AuditingTime>'2013-01-01' and b.ID>0 and Auditing=2

group by CONVERT(varchar(7),AuditingTime,20) print @sql declare @sql2 varchar(8000)='' set @sql2=' select *from (

select Url, CONVERT(varchar(7),AuditingTime,20) AuditingTime,SUM(Quality) Quality from  tb_order as a left join  tb_WebSiteInfo as b on a.WebSiteInfoID=b.ID left join  tb_OrderList as c on c.OrderID=a.ID where b.ID>0 and Auditing=2

group by Url, CONVERT(varchar(7),AuditingTime,20)

) as hh pivot (sum(Quality) for AuditingTime in (' + @sql + ')) b'

print @sql2

exec(@sql2)

相關(guān)文章

最新評(píng)論

舒兰市| 西宁市| 云和县| 元阳县| 铜川市| 昆山市| 兴文县| 邯郸县| 新民市| 林芝县| 大悟县| 玛纳斯县| 阿克陶县| 靖远县| 齐齐哈尔市| 开阳县| 宁河县| 庆元县| 泗阳县| 芜湖县| 珲春市| 定州市| 聂拉木县| 宜兴市| 云和县| 双江| 融水| 桃园县| 武山县| 博爱县| 海安县| 潞西市| 梁山县| 望都县| 德安县| 扎赉特旗| 海兴县| 若羌县| 荣昌县| 东乌珠穆沁旗| 枞阳县|