Re: How to select all top 1s from different group in a view
- From: "adam" <adam@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 5 Jan 2006 10:48:07 -0800
Hi Steve,
Thank for your reply.
Sorry, I should have layout my view in more clear way. Here is the view:
CONTRACT_KEY END_DATE STEP
1 <NULL> 1
1 2/5/2006 2
1 3/7/2006 3
2 3/1/2005 1
2 3/1/2005 2
2 <NULL> 3
3 <NULL> 1
3 <NULL> 2
3 <NULL> 3
How could I wrote a query to generate the following result:
CONTRACT_KEY END_DATE STEP
1 3/7/2006 3
2 3/1/2005 2
3 <NULL> 1
Thanks so much again!
-adams
"Steve Kass" wrote:
> A pattern for this, assuming no NULLs in your columns, is
>
> select
> Contract_KEY, Step
> from yourTable as T1
> where not exists (
> select * from yourTable as T2
> where T2.Contract_KEY = T1.Contract_KEY
> and T2.Step < T1.Step
> )
>
> Steve Kass
> Drew University
>
> adam wrote:
>
> >Hi SQL Query Guru,
> >
> >I have a view like this:
> >
> >Contract_KEY Step
> >1 1
> >1 3
> >2 1
> >2 5
> >2 4
> >
> >How do I write a query to retrieve the following result:
> >1 3
> >2 5
> >
> >Thanks very much!
> >
> >-adams
> >
> >
>
.
- Follow-Ups:
- Re: How to select all top 1s from different group in a view
- From: Hugo Kornelis
- Re: How to select all top 1s from different group in a view
- References:
- Re: How to select all top 1s from different group in a view
- From: Steve Kass
- Re: How to select all top 1s from different group in a view
- Prev by Date: Re: Update 'Date': Set Day(Date) to a Certain Number
- Next by Date: Re: Update 'Date': Set Day(Date) to a Certain Number
- Previous by thread: Re: How to select all top 1s from different group in a view
- Next by thread: Re: How to select all top 1s from different group in a view
- Index(es):
Relevant Pages
|
|