gpt4 book ai didi

连接的 SQL 限制

转载 作者:行者123 更新时间:2023-12-04 15:48:55 28 4
gpt4 key购买 nike

我在获取下一个查询的第一行时遇到了问题:

Select mar.Title MarketTitle, ololo.NUMBER, ololo.Title from Markets mar
JOIN(
Select emp.Employee_ID, emp.Market_id, ppp.Title, ppp.NUMBER from Employees emp
JOIN(
select pur.Employee_id Empl,Pro.Title Title, COUNT(pur.Product_id) NUMBER from Purchase pur
LEFT JOIN
Payments pay ON pay.Payment_ID = pur.Payment_ID AND pay.Date > DATEADD(month, -1, GETDATE())
RIGHT JOIN Products pro
ON pur.Product_id = pro.Product_ID
GROUP BY Pro.Title, pur.Employee_id) ppp ON ppp.Empl = emp.Employee_id) ololo
ON mar.Market_ID = ololo.Market_id
ORDER BY NUMBER DESC

我尝试了很多插入“limit 1”的组合,但都出错了。谁能帮忙?

最佳答案

LIMIT 不适用于 SQL Server

使用TOP 1相反:

SELECT TOP 1 mar.Title MarketTitle, ololo.NUMBER, ololo.Title from Markets mar
JOIN(
Select emp.Employee_ID, emp.Market_id, ppp.Title, ppp.NUMBER from Employees emp
JOIN(
select pur.Employee_id Empl,Pro.Title Title, COUNT(pur.Product_id) NUMBER from Purchase pur
LEFT JOIN
Payments pay ON pay.Payment_ID = pur.Payment_ID AND pay.Date > DATEADD(month, -1, GETDATE())
RIGHT JOIN Products pro
ON pur.Product_id = pro.Product_ID
GROUP BY Pro.Title, pur.Employee_id) ppp ON ppp.Empl = emp.Employee_id) ololo
ON mar.Market_ID = ololo.Market_id
ORDER BY NUMBER DESC

OFFSET-FETCH使用 SQL Server 2012+:

SELECT  mar.Title MarketTitle, ololo.NUMBER, ololo.Title from Markets mar
JOIN(
Select emp.Employee_ID, emp.Market_id, ppp.Title, ppp.NUMBER from Employees emp
JOIN(
select pur.Employee_id Empl,Pro.Title Title, COUNT(pur.Product_id) NUMBER from Purchase pur
LEFT JOIN
Payments pay ON pay.Payment_ID = pur.Payment_ID AND pay.Date > DATEADD(month, -1, GETDATE())
RIGHT JOIN Products pro
ON pur.Product_id = pro.Product_ID
GROUP BY Pro.Title, pur.Employee_id) ppp ON ppp.Empl = emp.Employee_id) ololo
ON mar.Market_ID = ololo.Market_id
ORDER BY NUMBER DESC
OFFSET 0 ROWS
FETCH FIRST 1 ROW ONLY

关于连接的 SQL 限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33964884/

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