Mysql中top命令的使用

it2024-03-22  58

一、背景介绍

使用Navicat Premium测试sql语句的时候发现报错提示

[SQL] select u.* from `user` u,score s where u.username=s.Name and s.Score=(select top 5 n.Score from score n order by Score desc) [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '5 n.Score from score n order by Score desc)' at line 1

二、解决问题

上述错误产生原因是由于 mysql 中 select top 用法 和 sqlserver 有所区别

如果需要在mysql中实现select top功能,使用方法为:select * from tablename limit M,N

其中,M表示从(M+1)条记录开始,N表示返回的记录条数

最新回复(0)