Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8991917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:50:14+00:00 2026-06-15T22:50:14+00:00

this is my first post here. I’m working with cheques, i have this in

  • 0

this is my first post here.
I’m working with cheques, i have this in the Oracle 11g database

 WITH cheques AS (
    SELECT 1 ch_no,'U' ch_status FROM dual UNION ALL
    SELECT 2 ch_no,'U' ch_status FROM dual UNION ALL
    SELECT 3 ch_no,'T' ch_status FROM dual UNION ALL
    SELECT 4 ch_no,'T' ch_status FROM dual UNION ALL
    SELECT 5 ch_no,'U' ch_status FROM dual UNION ALL
    SELECT 6 ch_no,'U' ch_status FROM dual UNION ALL
    SELECT 7 ch_no,'C' ch_status FROM dual UNION ALL
    SELECT 8 ch_no,'U' ch_status FROM dual UNION ALL
    SELECT 9 ch_no,'U' ch_status FROM dual UNION ALL
    SELECT 10 ch_no,'C' ch_status FROM dual UNION ALL
    SELECT 11 ch_no,'U' ch_status FROM dual UNION ALL
    SELECT 12 ch_no,'U' ch_status FROM dual UNION ALL
    SELECT 13 ch_no,'X' ch_status FROM dual UNION ALL
    SELECT 14 ch_no,'X' ch_status FROM dual UNION ALL
    SELECT 15 ch_no,'T' ch_status FROM dual UNION ALL
    SELECT 16 ch_no,'U' ch_status FROM dual UNION ALL
    SELECT 17 ch_no,'U' ch_status FROM dual UNION ALL
    SELECT 18 ch_no,'I' ch_status FROM dual UNION ALL
    SELECT 19 ch_no,'I' ch_status FROM dual UNION ALL
    SELECT 20 ch_no,'U' ch_status FROM dual
 )

I want tho get them in this way:

Status  Min Max
U   1   2
U   5   6
U   8   9
U   11  12
U   16  17
U   20  20
C   7   7
C   10  10
T   3   4
T   15  15
X   13  14
I   18  19

So, In Reporting Services 2008,i will be able to show them like this:

U       C       T       X       I   
Min Max Min Max Min Max Min Max Min Max
1   2   7   7   3   4   13  14  18  19
5   6   10  10  15  15              
8   9                               
11  12                              
16  17                              
20  20      

The question here is how to get this, how to get the min and max of each cheque based on their status?
I have searched, but i couldn’t find anything.

Sorry for my english.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:50:15+00:00Added an answer on June 15, 2026 at 10:50 pm

    This isn’t a straightforward problem and needs a number of steps.

    1. use lag to set a ‘flag’ at the start of each contiguous block of ch_no with the same ch_status
    2. use sum as an analytic with an order by (which changes the default window to unbounded preceeding) to give each contiguous block a unique identifier
    3. finally use a regular group by to calculate the min & max for each block

    Query:

    WITH cheques AS (
        SELECT 1 ch_no,'U' ch_status FROM dual UNION ALL
        SELECT 2 ch_no,'U' ch_status FROM dual UNION ALL
        SELECT 3 ch_no,'T' ch_status FROM dual UNION ALL
        SELECT 4 ch_no,'T' ch_status FROM dual UNION ALL
        SELECT 5 ch_no,'U' ch_status FROM dual UNION ALL
        SELECT 6 ch_no,'U' ch_status FROM dual UNION ALL
        SELECT 7 ch_no,'C' ch_status FROM dual UNION ALL
        SELECT 8 ch_no,'U' ch_status FROM dual UNION ALL
        SELECT 9 ch_no,'U' ch_status FROM dual UNION ALL
        SELECT 10 ch_no,'C' ch_status FROM dual UNION ALL
        SELECT 11 ch_no,'U' ch_status FROM dual UNION ALL
        SELECT 12 ch_no,'U' ch_status FROM dual UNION ALL
        SELECT 13 ch_no,'X' ch_status FROM dual UNION ALL
        SELECT 14 ch_no,'X' ch_status FROM dual UNION ALL
        SELECT 15 ch_no,'T' ch_status FROM dual UNION ALL
        SELECT 16 ch_no,'U' ch_status FROM dual UNION ALL
        SELECT 17 ch_no,'U' ch_status FROM dual UNION ALL
        SELECT 18 ch_no,'I' ch_status FROM dual UNION ALL
        SELECT 19 ch_no,'I' ch_status FROM dual UNION ALL
        SELECT 20 ch_no,'U' ch_status FROM dual
     )
    select ch_status, min(ch_no), max(ch_no)
    from( select ch_no, ch_status, sum(changed_flag) over (order by ch_no) as grp
          from( select ch_no, ch_status, 
                       decode(ch_status,lag(ch_status) over(order by ch_no),0,1) 
                         as changed_flag
                from cheques ) )
    group by ch_status, grp
    order by ch_status, min(ch_no)
    

    Results:

    | CH_STATUS | MIN(CH_NO) | MAX(CH_NO) |
    ---------------------------------------
    |         C |          7 |          7 |
    |         C |         10 |         10 |
    |         I |         18 |         19 |
    |         T |          3 |          4 |
    |         T |         15 |         15 |
    |         U |          1 |          2 |
    |         U |          5 |          6 |
    |         U |          8 |          9 |
    |         U |         11 |         12 |
    |         U |         16 |         17 |
    |         U |         20 |         20 |
    |         X |         13 |         14 |
    

    SQL Fiddle here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello all this is my first post here i have been working in an
This is my first post here, recently i have been working with JSF2.0 with
This is my first post here. I have a problem. I need to take
This is my first post here, so please bear with me... I have discovered
This is my first post here, o let me say hi :) I have
This is my first post here and I wanted to get some input from
This is my first post here so kindly pardon any mistakes that I have.
This is my first post here. I have been reading posts here since I
this is my first post here. I'm excited to finally take part. I'm working
This is my first post here so go easy. I am trying to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.