我想在数据库中取最大的前三个值,请问如何去写。。?谢谢、SELECT a FROM yourTable ORDER BY a DESC LIMIT 3 问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧)
select * from yourTable t where b in (select b from yourTable where a=t.a order by b desc limit 3); select t1.a,t1.b from yourtable t1 inner join yourTable t2 on t1.a=t2.a and t1.b<=t2.b group by t1.a,t1.b having count(*)<=3
select * from tt limit 6,3
FROM yourTable
ORDER BY a DESC LIMIT 3
a b
1 10
1 11
1 12
1 13
1 14
2 5
2 6
2 7
2 8
2 9
3 100
3 200
3 300
3 400
3 500
我现在要的结果是这样,a字段中最大的3个b值,结果如下:
a b
1 12
1 13
1 14
2 7
2 8
2 9
3 300
3 400
3 500是这样的,不知道应该怎么写的说,谢谢。。
问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧)
from yourTable t
where b in (select b from yourTable where a=t.a order by b desc limit 3);
select t1.a,t1.b
from yourtable t1 inner join yourTable t2 on t1.a=t2.a and t1.b<=t2.b
group by t1.a,t1.b
having count(*)<=3