日期:2014-05-16  浏览次数:20589 次

mysql如何取一张表里每个OBJ的前3 个数值
id name value
1 a 3
2 a 3.2
3 a 5
4 a 6
5 a 3
6 b 7
7 b 3
8 b 2
9 b 4
10 c 8
11 c 9
得到的结果
id name value
1 a 3
2 a 3.2
3 a 5
6 b 7
7 b 3
8 b 2
10 c 8
11 c 9
根据id的排序取前3

------解决方案--------------------
SQL code
select *
from tb A
where  (select count(*) from tb where A.name=name and A.id>id)<3