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

0

Please login or register to vote for this query.

(click on this box to dismiss)

Signal Processing Meta

Q&A about the site for practitioners of the art and science of signal, image and video processing

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

CREATE TABLE #we
([Department] char(255), 
     [SumOfSalesQ1] int, 
     [Percent2016] int, 
     [PercentTotal] int)
;
 
 declare @sq1 int, @mq1 int, @s16 int, @m16 int, @ts int
 
 set @sq1 = (select sum(totalPrice)
      from #yt
      where store = 101 and week = 1)
      
 set @mq1 = (select sum(totalPrice)
      from #yt
      where store = 102 and week = 1)




      
INSERT INTO #we
  ([Department], [SumOfSalesQ1], [Percent2016], [PercentTotal])
VALUES
    ('sport', @sq1, 2, 3),
    ('music' , @mq1, 3, 6)
;

 set @s16 = @sq1/@mq1
select @s16

Enter Parameters

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