表结构
Table_Name test
id 自动增长 主键 --学号
name 字符 --姓名
class int --班级
date datetime --入学时间现要求需要取得 每个班级中前N个入学的同学姓名、学号、班级、入学时间等信息。
目前在其他数据库中已经实现
select * from test where test.id in (select top N id from test as t where test.class=t.class order by t.class,t.date asc) order by test.class,test.date但在MYSQL中不支持TOP关键字 用LIMIT又无法实现 请教如何解决。。谢谢
select * from test where test.id in (select id from test as t where test.class=t.class order by t.class,t.date asc limit N) order by test.class,test.date
Table_Name test
id 自动增长 主键 --学号
name 字符 --姓名
class int --班级
date datetime --入学时间现要求需要取得 每个班级中前N个入学的同学姓名、学号、班级、入学时间等信息。
目前在其他数据库中已经实现
select * from test where test.id in (select top N id from test as t where test.class=t.class order by t.class,t.date asc) order by test.class,test.date但在MYSQL中不支持TOP关键字 用LIMIT又无法实现 请教如何解决。。谢谢
select * from test where test.id in (select id from test as t where test.class=t.class order by t.class,t.date asc limit N) order by test.class,test.date
select top 8 * from table1
go
MYSQL:
select * from table1 limit 5;
你这语句不需要子查询
from test t
where N>(select count(*) from test where class=t.class and `date`<t.date)