how to find summary value by range
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: how to find summary value by range

  1. #1
    Join Date
    Mar 2011
    Posts
    2

    how to find summary value by range

    Hi,

    please help me

    this is my table

    create table sequence (
    id int not null primary key
    );

    insert into sequence(id) values
    (1), (2), (3), (4), (6), (7), (8), (9),
    (10), (15), (16), (17), (18), (19), (20),(22);

    i need the answer to group the sequence like this


    start_number | end_number | count
    1 | 4 | 4
    6 | 10 | 5
    15 | 20 | 6
    22 | 22 | 1


    what should i do?

  2. #2
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,554
    This is homework, isn't it?

    There are multiple alternatives to solve this particular scenario, question is... what is your teacher talking about these days, is it grouping? pivoting? unions? analytics?
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  3. #3
    Join Date
    Mar 2011
    Posts
    2
    no no PAVB.
    this is a part of my work to make summary report.
    But this example is a reproduce data. my data just similar with this case.
    thx

  4. #4
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,554
    On the top of my mind, easiest way will be to create a secondary table describing each range, join both tables grouping by such ranges described in secondary table.
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

Posting Permissions

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



Click Here to Expand Forum to Full Width