CREATE TABLE #yt ([Store] int, [Week] int, [xCount] int,[...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Drones and Model Aircraft Meta

Q&A for experienced flyers, pilots, and builders of drones and model aircraft

CREATE TABLE #yt
    ([Store] int, [Week] int, [xCount] int,[ycount] int)
;
    
INSERT INTO #yt
    ([Store], [Week], [xCount],[ycount])
VALUES
    (102, 1, 96,4),
    (101, 1, 138,4),
    (105, 1, 37,4),
    (109, 1, 59,4),
    (101, 2, 282,5),
    (102, 2, 212,5),
    (105, 2, 78,5),
    (109, 2, 97,5),
    (105, 3, 60,6),
    (102, 3, 123,6),
    (101, 3, 220,6),
    (109, 3, 87,6)
;


select *
from 
(
  select store, week, xCount,ycount
  from #yt
) src
pivot
(
  sum(xcount)
  for week in ([1], [2], [3])
) piv;

Enter Parameters

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