Results 1 to 3 of 3

Thread: Adding rows

  1. #1
    Join Date
    Aug 2008
    Posts
    464

    Unanswered: Adding rows

    Hi

    I'm looking for some advice on how to select data as follows. Hopefully someone will be able to help.

    I have a table like:

    Code:
    DATETIME                    CLASS     CELL  CALLS
    05/12/2010 1:00               A           1       10
    05/12/2010 1:00               B           1       20
    05/12/2010 1:00               C           1       15
    05/12/2010 1:00               D           1       12
    05/12/2010 1:00               E           1       10
    05/12/2010 1:15               A           1       10
    05/12/2010 1:15               B           1       20
    05/12/2010 1:15               C           1       15
    05/12/2010 1:15               D           1       12
    05/12/2010 1:15               E           1       10

    Now I want to select the calls as:

    (A+B+C)-(D+E)

    and group by datetime,cell

    Will appreciate some expert advice. Thanks.

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Something like this:
    Code:
    select datetime, cell,
      sum(case when class = 'A' then calls
               when class = 'B' then calls
               when class = 'C' then calls
               when class = 'D' then -calls
               when class = 'E' then -calls
          end
         ) result
    from your_table
    group by datetime, cell

  3. #3
    Join Date
    Aug 2008
    Posts
    464
    Thanks a lot. Really appreciated.

Posting Permissions

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