Method 1:
Copy codeThe Code is as follows:
Select * from (select Url, case when Month = 01 then 'february 'when Month = 02 then' February 'when Month = 03 then' February 'when Month = 04 then' February 'when Month = 05 then' February 'When Month = 06 then' February 'when Month = 07 then' February 'when Month = 08 then' February 'when Month = 09 then' February 'when Month = 10 then' February 'When Month = 11 then' November 'when Month = 12 then' December'
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. webSiteInfoID = B. ID left join tb_OrderList as c on c. orderID =. ID where AuditingTime> '2017-01-01 'and B. ID> 0 and Auditing = 2
Group by Url, DATENAME (M, AuditingTime) as h) as hh
Values (sum (Quality) for month in ([January], [February], [March], [April], [May], [June], [July], [August], [September], [October], [November], [December]) as
Method 2:
Copy codeThe Code is as follows:
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. webSiteInfoID = B. ID left join tb_OrderList as c on c. orderID =. ID where AuditingTime> '2017-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. webSiteInfoID = B. ID left join tb_OrderList as c on c. orderID =. ID where B. ID> 0 and Auditing = 2
Group by Url, CONVERT (varchar (7), AuditingTime, 20)
) As hh Merge (sum (Quality) for AuditingTime in ('+ @ SQL +') B'
Print @ sql2
Exec (@ sql2)