Overlapping Ranges- Query Alternative - Mailing list pgsql-sql

From Ozer, Pam
Subject Overlapping Ranges- Query Alternative
Date
Msg-id 216FFB77CBFAEE4B8EE4DF0A939FF1D101839A@mail-001.corp.automotive.com
Whole thread Raw
Responses Re: Overlapping Ranges- Query Alternative
List pgsql-sql

I have the following problem:

 

Create temp table ranges (Groups int, ColumnA int);

Insert into ranges

Values(2,45);

 

Select Groups,

Case when ColumnA between 0 and 19 then 0

     when ColumnA >=20 then 20

     when ColumnA >=30 then 30

     when ColumnA>=40 then 40

     when ColumnA>=50 then 50 end MinRange

from ranges

 

Results:

Groups minrange

2;20

 

What I want Is : One column can fall into multiple ranges.  For example 45 >20, 30, and 40 so I want the following results

2;20

2;30

2;40

 

I know I could do a union with each range but is there any way to bring back all ranges in one query?  I need to bring back the values in one column so having separate columns for each range is not an option.

 

Thank you in advance for any help

 

Pam Ozer



pgsql-sql by date:

Previous
From: Bryce Nesbitt
Date:
Subject: "slow lock" log in addition to log_min_duration_statement ?
Next
From: Andreas Gaab
Date:
Subject: Re: Overlapping Ranges- Query Alternative