SQL - select 具有最低列值的组的行由其他分组
SQL - select row of group with lowest column value grouped by other
你好,
我有这个table
a
b
c
One
hello
1
two
hello
2
three
hi
3
four
hi
4
我想select按B值分组的最小“C”值行
我的输出应该是
a
b
c
One
hello
1
three
hi
3
我怎么能select他们?
这通常是 row_number
的解决方案
select a, b, c
from (
select *,
Row_Number() over(partition by b order by c) rn
from t
)t
where rn=1
你好,
我有这个table
a | b | c |
---|---|---|
One | hello | 1 |
two | hello | 2 |
three | hi | 3 |
four | hi | 4 |
我想select按B值分组的最小“C”值行
我的输出应该是
a | b | c |
---|---|---|
One | hello | 1 |
three | hi | 3 |
我怎么能select他们?
这通常是 row_number
select a, b, c
from (
select *,
Row_Number() over(partition by b order by c) rn
from t
)t
where rn=1