In SQL, how can I select the minimum value of a column a
(integer) where the column b
(integer) is the maximum value for that column, using only one select ?
SELECT MIN(a) OVER (PARTITION BY MAX(b)) as res #seems to be ill-formed
FROM table
For instance
a | b |
---|---|
1 | 1 |
1 | 3 |
2 | 3 |
should return
res |
---|
1 |
order by
and limit
should be good enough here:
select a
from mytable
order by b desc, a
limit 1