Pivot on WeekDay Example

0

Please login or register to vote for this query.

(click on this box to dismiss)

Motor Vehicle Maintenance and Repair Meta

Q&A about the site for mechanics and DIY enthusiast owners of cars, trucks, and motorcycles

/*

SELECT OwnerUserID, [Monday] FROM 
(SELECT 
SCORE , OwnerUserID, DATENAME(weekday, CreationDate) day
from 
       Posts 
where  
OwnerUserID in (1,2,3,4,5)) p
PIVOT (
SUM (SCORE ) Score 
FOR  day In ('Monday', 'Tuesday', 'Wednessday', 'Thursday', 'Friday')
) pvt
*/
SELECT 
SCORE , OwnerUserID, DATENAME(weekday, CreationDate) day
from 
       Posts 
where  
OwnerUserID in (1,2,3,4,5)

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results