select count(*) from 表tab where points>=(select points from 表tab where id=123)
tab id points text 1 156 'asd' 2 19 'ssdfs' 3 27 'dfgdf' 4 210 'sdsda' 查询id为4的记录 输出结果‘sdsda’ 1
select * from ( select a.id,a.points,a.text,count(b.id) as pm from tt a left join tt b on a.points<=b.points group by a.id,a.points,a.text) aa where id=4
呃 灰常感谢WWWWA! 我再试试优化一下 看看能不能不用子查询
select count(*) from tab a inner join tab b on a.points<=b.points where a.id=4
id points text
1 156 'asd'
2 19 'ssdfs'
3 27 'dfgdf'
4 210 'sdsda'
查询id为4的记录 输出结果‘sdsda’ 1
select a.id,a.points,a.text,count(b.id) as pm from tt a left join tt b
on a.points<=b.points
group by a.id,a.points,a.text) aa where id=4
呃 灰常感谢WWWWA! 我再试试优化一下 看看能不能不用子查询
from tab a inner join tab b on a.points<=b.points
where a.id=4