Re: select a where min(b)
From: Shakespeare <whatsin_at_xs4all.nl>
Date: Tue, 30 Mar 2010 13:22:13 +0200
Message-ID: <4bb1deef$0$22919$e4fe514c_at_news.xs4all.nl>
Op 30-3-2010 12:40, steph schreef:
> I've got a table STEP defined as (a number, b number). It contains
> these data:
>
> A,B
> 1,1
> 1,2
> 1,3
> 4,3
> 2,3
> 2,1
> 5,0
>
> Now I want to find this value of A where B is at it's minimum.
>
> I made up the following SQL:
>
> select a
> from step
> where b=
> (
> select min(b)
> from step
> )
>
> But I suspect there must be a much more elegant way to achieve this.
> Is there?
>
> thanks,
> Stephan
Date: Tue, 30 Mar 2010 13:22:13 +0200
Message-ID: <4bb1deef$0$22919$e4fe514c_at_news.xs4all.nl>
Op 30-3-2010 12:40, steph schreef:
> I've got a table STEP defined as (a number, b number). It contains
> these data:
>
> A,B
> 1,1
> 1,2
> 1,3
> 4,3
> 2,3
> 2,1
> 5,0
>
> Now I want to find this value of A where B is at it's minimum.
>
> I made up the following SQL:
>
> select a
> from step
> where b=
> (
> select min(b)
> from step
> )
>
> But I suspect there must be a much more elegant way to achieve this.
> Is there?
>
> thanks,
> Stephan
If you want only one row returned :
select a,b from
(select a,b,row_number() over (order by b,a) rown from step)
where rown =1
Shakespeare Received on Tue Mar 30 2010 - 06:22:13 CDT