-2

I have a table like this

1

and need to aggregate like below

2

DROP TABLE IF EXISTS #tmp2
SELECT item, Quantity, Seconds
SUM(Quantity) AS total_quantity,
--SUM(Seconds) AS total_seconds,
--SUM(Seconds)/3600 AS items_per_hour
INTO #tmp2
FROM #tmp1
GROUP BY item
rgirl
  • 1
  • 4

2 Answers2

0

if you want the sun of a column you can directly invoke the same column in select

    SELECT item

    SUM(Quantity) AS total_quantity,
    --SUM(Seconds) AS total_seconds,
    --SUM(Seconds)/3600 AS items_per_hour
    INTO #tmp2
    FROM #tmp1
    GROUP BY item
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
0

For aggregation you do not need Quantity and Seconds. Try the following

SELECT 
   item,
   SUM(Quantity) AS total_quantity,
   SUM(Seconds) AS total_seconds,
   SUM(Seconds)/3600 AS items_per_hour
FROM #tmp1
GROUP BY 
  item
zealous
  • 7,336
  • 4
  • 16
  • 36