gpt4 book ai didi

mysql - 子查询在mysql中返回多于1行

转载 作者:行者123 更新时间:2023-11-29 22:27:51 25 4
gpt4 key购买 nike

我正在执行以下查询并收到错误“子查询返回超过 1 行”

我的查询是

SELECT pkTicketID,
TicketReplyDateAdded,
TIMESTAMPDIFF(DAY, TicketReplyDateAdded, now()) as NumberOfDays
FROM tickets as T
LEFT JOIN ticket_replies as TR ON T.fkTicketReplyID=TR.pkTicketReplyID
WHERE 1 AND T.fkEmployeeID = '4'
AND (SELECT TIMESTAMPDIFF(DAY, TicketReplyDateAdded, now()) as NumberOfDays
FROM tickets as T
LEFT JOIN ticket_replies as TR
ON T.fkTicketReplyID=TR.pkTicketReplyID
) = 7
AND T.TicketStatus = 'Replied'
ORDER BY pkTicketReplyID DESC

感谢您的帮助。欧麦尔

最佳答案

您可以通过限制子查询仅返回一行来修复此错误,如下所示:

SELECT pkTicketID,TicketReplyDateAdded,
TIMESTAMPDIFF(DAY, TicketReplyDateAdded,now()) as NumberOfDays
FROM tickets as T
LEFT JOIN ticket_replies as TR
ON T.fkTicketReplyID=TR.pkTicketReplyID
WHERE 1
AND T.fkEmployeeID = '4'
AND (SELECT TIMESTAMPDIFF(DAY, TicketReplyDateAdded, now()) as NumberOfDays
FROM tickets as T LEFT JOIN ticket_replies as TR
ON T.fkTicketReplyID=TR.pkTicketReplyID
LIMIT 1) = 7
AND T.TicketStatus = 'Replied'
ORDER BY pkTicketReplyID DESC

(添加“限制 1”)

关于mysql - 子查询在mysql中返回多于1行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30096074/

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