例如 table1(a,b,c,d)
a b c d
1 0 c1 d1
1 1 c2 d2
1 3 c3 d3
4 0 c4 d4
5 1 c5 d5
5 2 c6 d6
6 1 c7 d7
6 4 c8 d8
我要得到的是按a分组,在每个分组中取b值最大的一条记录,就是
a b c d
1 3 c3 d3
4 0 c4 d4
5 2 c6 d6
6 4 c8 d8
sql语句如何写?
测试语句:select * from table1 a where b=(select max(b) from table1 where a=a.a)
通过。