Thread: Grouping

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Grouping


    Hi,

    I have a DB with a column in a table holding duration times. I would like to compose a SQL which gives me the count of defined ranges of durations.

    Lets say 0 - 60 minutes, 61 to 180 minutes, 181 - 600 minutes and 601 and above are the ranges and I need the counts of each range in one SQL-statement.

    Is there a way to achieve this? In the moment I am too blind to see...

    Thanx for any hint!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    Paris Uppland
    Posts
    2,374
    Rep Power
    391
    You can use a case expression

    Code:
    select sum(case when <columnHoldingdurationTimes> between 0 and 60 then 1 else 0 end),
           sum(case when <columnHoldingdurationTimes> between 61 and 180 then 1 else 0 end), ...
      from <tableHoldingDurationTimes>
    Change names as apropriate.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Red face


    Originally Posted by swampBoogie
    You can use a case expression

    Code:
    select sum(case when <columnHoldingdurationTimes> between 0 and 60 then 1 else 0 end),
           sum(case when <columnHoldingdurationTimes> between 61 and 180 then 1 else 0 end), ...
      from <tableHoldingDurationTimes>
    Change names as apropriate.
    grrr...sure - that's a way. As I wrote: too blind to see...

    Thanx a lot!

IMN logo majestic logo threadwatch logo seochat tools logo