mysql 查询记录 排序之后 查看指定记录 在数据库中位于第几行

2025-05-05 00:50:18
推荐回答(2个)
回答1:

1.创建一个测试版图表

创建表test_limit(idint,值varchar(100)),如下图。

2.插入测试数据度,知道6条记录;

Insertintotest_limitvalues(1,“v1”);

Insertintotest_limitvalues(2、“v2”);

Insertintotest_limitvalues(3,'thev3);

Insertintotest_limitvalues(4,'thev4');

Insertintotest_limitvalues(5v5);

Insertintotest_limitvalues(6'6');

3.查询表全数据,共可以找到6个数据,选择*fromtest_limitt,如下图。

4.编写正确的语句,指定3条需要查询的数据;

Select*fromtest_limitlimit3;

回答2:

SELECT count(*) from (SELECT * FROM `dede_archives` ORDER BY goodpost DESC) as a where goodpost >= (SELECT goodpost from `dede_archives` where id = 'ID')