select id,max(hitnum),group from table group by group,id,
select id,max(hitnum),group from table group by group,id
to xiaha3(夏) : 我的测试记录有3个组,8条记录,用你的方法 返回全部记录, 谢谢你的回复~~
如果一组中有两个最大的hitnum 可以取出任意一个 (或者可以忽略这个可能性) 如测试记录 id hitnum grp 1 4 a 2 5 a 3 6 a 4 6 b 5 7 b 6 8 b 7 8 c 8 9 c 取出的值是 id hitnum grp 3 6 a 6 8 b 8 9 c 谢谢了~
select a.id,a.hitnum,a.grp from test a,(select max(hitnum) as hitnum,grp from test b group by grp) b where a.hitnum=b.hitnum and a.grp=b.grp 这样写:可以取出各组中所有最大的hitnum的id 但是如果一组中(如a组,有两个最大的hitnum,这中写法就取出了 a组中的2条最大的hitnum的id) 而我只想要各组中一条最大的hitnum的id,如何解决 ?
select max(a.id) ,a.hitnum,a.grp from test a,(select max(hitnum) as hitnum,grp from test b group by grp) b where a.hitnum=b.hitnum and a.grp=b.grp group by a.hitnum,a.grp
select id,max(hitnum),group from table group by group,id
我的测试记录有3个组,8条记录,用你的方法 返回全部记录, 谢谢你的回复~~
id hitnum grp
1 4 a
2 5 a
3 6 a
4 6 b
5 7 b
6 8 b
7 8 c
8 9 c
取出的值是
id hitnum grp
3 6 a
6 8 b
8 9 c
谢谢了~
select a.id,a.hitnum,a.grp from test a,(select max(hitnum) as hitnum,grp from test b group by grp) b
where a.hitnum=b.hitnum and a.grp=b.grp 这样写:可以取出各组中所有最大的hitnum的id 但是如果一组中(如a组,有两个最大的hitnum,这中写法就取出了 a组中的2条最大的hitnum的id)
而我只想要各组中一条最大的hitnum的id,如何解决 ?
where a.hitnum=b.hitnum and a.grp=b.grp group by a.hitnum,a.grp