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)

Role-playing Games

Q&A for gamemasters and players of tabletop, paper-and-pencil role-playing games

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


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

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results