gpt4 book ai didi

php - 使用 mysql 选择前 10 个最近的事情

转载 作者:行者123 更新时间:2023-12-01 00:04:56 25 4
gpt4 key购买 nike

我希望获得最近提交的十个补丁(top 10 patchID desc)从以下查询开始,我在 10 上收到错误。错误是语法错误、意外的 NUM、预期的 END_OF_INPUT 或“;”。会不会在以下查询中导致此错误?

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

最佳答案

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

关于php - 使用 mysql 选择前 10 个最近的事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17328311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com