Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006

    Unanswered: problem with sum of a category

    Hi everybody

    Have this situation that I have to sum only some categories in a field.
    I usually get the sum of each category in two queries is it possible the I sum up in only one query both categories.

    description numberDays Category

    first 2 1
    second 3 2
    third 5 1
    fourth 1 2

    SELECT description, sum(numberDays) as sumDays from table
    where category=1
    GROUP BY description

    SELECT description, sum(numberDays) as sumDays from table
    where category=2
    GROUP BY description


  2. #2
    Join Date
    May 2009
    Provided Answers: 1
    alexiop, it is hard to tell with your example data. What you have wouldn't really sum anything since all the Description values are unique. What you can do in one query is:
    SELECT Category, SUM(NumberOfDays) AS SumDays
    FROM table-name
    WHERE Category IN(1, 2)
    GROUP BY Category
    Category SumDays
    1        7
    2        4

  3. #3
    Join Date
    Dec 2008
    use union between two select statements

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts