rebump
3/20/2007 3:28:00 AM
On Mar 19, 10:25 pm, "xyb" <xiangyua...@gmail.com> wrote:
> On 3?20?, ??11?14?, "rebump" <reb...@gmail.com> wrote:
>
>
>
>
>
> > On Mar 19, 10:06 pm, "xyb" <xiangyua...@gmail.com> wrote:
>
> > > On 3?20?, ??10?37?, "rebump" <reb...@gmail.com> wrote:> I should add to the above...SQL Server 2000 (i.e. no 2005 :( )
>
> > > > Thanks again,
> > > > rebump
>
> > > the main conception is to count mininum of mininum of id3,test code
> > > here:
> > > create table #t
> > > (
> > > ID1 int,
> > > ID2 int,
> > > ID3 int
> > > )
>
> > > insert into #t
> > > select 1005, 1, 37
> > > union select 1005, 2, 0
> > > union select 1005, 3, 0
> > > union select 1005, 4, 54
> > > union select 1005, 5, 38
> > > union select 1007, 1, 2
> > > union select 1009, 1, 1
> > > union select 1009, 2, 3
> > > union select 1010, 1, 1
> > > union select 1010, 2, 1
> > > union select 1010, 3, 2
> > > union select 1010, 4, 3
>
> > > select * from #t
>
> > > select id1,mid2=min(id2),mmid3 = min(mid3) from
> > > (
> > > select id1,id2,mid3=min(id3) from #t group by id1,id2 --order by id1
> > > ) as n1
> > > group by id1
>
> > > drop table #t
>
> > That was a quick response! It yields:
>
> > 1005, 1, 0
> > 1007, 1, 2
> > 1009, 1, 1
> > 1010, 1, 1
>
> > which is nearly what I was looking for:
>
> > 1005, 2, 0
> > 1007, 1, 2
> > 1009, 1, 1
> > 1010, 1, 1
>
> > A min(id3) for a give min(id2) for a given id1 with the same record
> > contents associated (i.e. not 1005, 1, 0). Am I asking for the
> > impossible as I am still scratching my head. I think it comes down to
> > a nested "top 1" nested under another "top 1" or a couple nested
> > subqueries with "min()" or such.
>
> > Thanks again,
> > rebump- ??????? -
>
> > - ??????? -
>
> e:)
> select a.id1,mid2=min(id2),a.mid3 from
> (
> select id1,id2,mid3=min(id3) from #t group by id1,id2
> ) a join
> (
> select id1,mmid3= min(mid3) from
> (
> select id1,id2,mid3=min(id3) from #t group by id1,id2-- order by id1
> ) as n1
> group by id1
> ) b
> on a.id1=b.id1 and a.mid3 = b.mmid3
> group by a.id1,a.mid3- Hide quoted text -
>
> - Show quoted text -
Holy mackeral!!! You're the winner kid! May the force be with you!
Thanks, I appreciate it greatly. I have to study you solution now.
Humbly yours,
rebump