PIVOT和UNPIVOT使用详解



参考:

http://database.51cto.com/art/201107/276189.htm


自己:


SELECT  CityName AS '城市' ,
        [0] ,
        [100] ,
        [300] ,
        [500] ,
        [1000] ,
        [5000],
  [0]+[100]+ [300]+[500]+ [1000]+ [5000] AS [总数]
FROM    ( SELECT    ID ,
                    CityName ,
                    BonusAmount
          FROM      BuyerLotteryDetailRecord
          WHERE     Status = 1
                    AND [LotteryDate] > '2015-07-05 18:00:00.000'
                    AND [LotteryDate] < '2015-07-06 18:00:00.000'
                    AND CityName <> '商洛'
        ) p  PIVOT
( COUNT(ID) FOR BonusAmount IN ( [0], [100], [300], [500], [1000], [5000] ) ) AS pvt
ORDER BY pvt.CityName;




阅读更多
个人分类: sqlserver
上一篇string转datetime
下一篇关于html控件button的onclick和onserverclick事件不能同时起作用问题
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭