CREATE TABLE #yt ([Store] int, [Week] varchar(max), [xCou...

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] varchar(max), [xCount] int)
;
    
INSERT INTO #yt
    ([Store], [Week], [xCount])
VALUES
    (102, 0-1, 96),
    (101, 0-1, 138),
    (105, 0-1, 37),
    (109, 0-1, 59),
    (101, 2-3, 282),
    (102, 2-3, 212),
    (105, 2-3, 78),
    (109, 2-3, 97),
    (105, 4-5, 60),
    (102, 4-5, 123),
    (101, 4-5, 220),
    (109, 4-5, 87)
;


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

Enter Parameters

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