0

I am trying to write a query to return the sum of call time for each specific category. There are only 3 categories and i only want 3 rows to be returned with the sum of time. I thought using the distinct would work, but it also applies to the minutes too.

How can I manipulate this query to only be distinct on category?

SELECT DISTINCT 
    category, SUM(calltime)
FROM 
    table
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

You're supposed to use GROUP BY instead of distinct

SELECT SUM(calltime)
FROM table
GROUP BY catagory
Teneff
  • 30,564
  • 13
  • 72
  • 103
  • if i am already grouping by date like this, do i just add the GROUP BY Catagory at the end also? SELECT catagory, SUM(calltime) FROM table GROUP BY DATEPART (wk, activity_date) and catagory – MidnightPolaris May 04 '16 at 22:53
  • @MidnightPolaris you can group by multiple columns or expressions like this `GROUP BY col1, col2, FN(col3)` which will multiply the rows returned – Teneff May 04 '16 at 22:57