我希望得到最近提交的10个补丁(前10个补丁ID)
从以下查询开始,我在10
上收到错误消息。错误是syntax error, unexpected NUM, expecting END_OF_INPUT, or ';'
。可能会在以下查询中导致此错误吗?
SELECT TOP 10 synth.*
FROM (
SELECT p.`id`,
p.`patchName`,
p.`description`,
p.`tfsID`,
p.`codeRelease`,
s.`name`,
d.`deployStatus`,
d.`deployedDate`,
t.`testedStatus`,
t.`testedDate`
FROM `patches` AS p
JOIN `deployed` AS d ON p.`id` = d.`PatchID`
JOIN `servers` AS s ON d.`serverID` = s.`id`
JOIN `tested` AS t ON p.`id` = t.`patchID`
) synth
ORDER BY synth.id DESC
答案 0 :(得分:8)
TOP 10
是MS SQL特有的东西,在MySQL中他们使用LIMIT
代替。
SELECT p.`id`,
p.`patchName`,
p.`description`,
p.`tfsID`,
p.`codeRelease`,
s.`name`,
d.`deployStatus`,
d.`deployedDate`,
t.`testedStatus`,
t.`testedDate`
FROM `patches` AS p
JOIN `deployed` AS d ON p.`id` = d.`PatchID`
JOIN `servers` AS s ON d.`serverID` = s.`id`
JOIN `tested` AS t ON p.`id` = t.`patchID`
ORDER BY p.`id` DESC
LIMIT 10
每个服务器的限制语法相当不同,这里有一个概述:
从第100行开始,显示10个结果(即101,102,103 ......)
PostgreSQL, MySQL and DB2: SELECT * FROM table LIMIT 10 OFFSET 100
Informix: SELECT SKIP 100 FIRST 10 FROM table
Microsoft SQL Server and Access: SELECT TOP 10 * FROM table -- skipping the offset here as it's a pain, search for it if you need it :)
Oracle: SELECT * FROM (SELECT *, ROW_NUMBER() OVER ORDER BY id) rnk FROM table) WHERE rnk BETWEEN 100 AND 110