SELECT
CreateTime as ' 日期 ',
isnull( [ 支付宝 ], 0) as ' 支付宝 ' ,
isnull( [ 手机短信 ], 0) as ' 手机短信 ',
isnull( [ 工商银行卡 ], 0) as ' 工商银行 ' ,
isnull( [ 建设银行卡 ], 0) as ' 建设银行 ',
isnull( [ 支付宝 ], 0) + isnull( [ 手机短信 ], 0) + isnull( [ 工商银行卡 ], 0) + isnull( [ 建设银行卡 ], 0) as ' 合计 '
FROM
(
SELECT CONVERT( VARCHAR( 10), CreateTime, 120) AS CreateTime,PayType, Money
FROM Inpours
) P
PIVOT (
SUM( Money)
FOR PayType IN
( [ 支付宝 ], [ 手机短信 ], [ 工商银行卡 ], [ 建设银行卡 ])
) AS T
ORDER BY CreateTime
结果如图: