gpt4 book ai didi

MySQL语法错误,但一切看起来都是正确的

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

这是 SQL 错误:

Error: 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 ') and (pi.perm_type='forum' and ( pi.perm_2='*' OR pi.perm_2 LIKE '%,4,%' )) and' at line 2

这是 SQL 查询:

SELECT t.tid AS id, t.title, t.last_poster_id AS id2,m.member_group_id, 
m.members_display_name AS statistic,pi.perm_2 FROM topics t LEFT JOIN members m ON (
m.member_id = t.last_poster_id )
LEFT JOIN permission_index pi ON ( pi.app='forums' AND pi.perm_type='forum' AND
pi.perm_type_id=t.forum_id ) WHERE t.forum_id NOT IN() AND (pi.perm_type='forum' AND (
pi.perm_2='*' OR pi.perm_2 LIKE '%,4,%' )) AND t.approved=1 AND (t.moved_to='' OR
t.moved_to IS NULL ) ORDER BY t.last_post DESC LIMIT 0,11

现在,这个查询在我的 MySQL 本地安装 (XAMPP) 上运行良好。

会不会是MySQL版本不同导致本次查询出现SQL错误?究竟是什么导致了错误?

  1. “LIKE”运算符?

  2. where 子句中的嵌套语句? (在()之间)

  3. 还有别的吗?

提前致谢!

最佳答案

你有一个空的 NOT IN

此外,您不需要 pi 上的 WHERE 条件之一,因为它在 LEFT JOIN 中。但是,外部表 pi 上 WHERE 中的 LIKE 过滤器将其更改为内部连接。

因此,您将需要它并修复您的 IN

SELECT 
t.tid AS id,
t.title,
t.last_poster_id AS id2,m.member_group_id,
m.members_display_name AS statistic,
pi.perm_2
FROM
topics t
LEFT JOIN
members m ON m.member_id = t.last_poster_id
LEFT JOIN
permission_index pi ON pi.app='forums' AND pi.perm_type='forum' AND
pi.perm_type_id=t.forum_id
AND
(pi.perm_2='*' OR pi.perm_2 LIKE '%,4,%')
WHERE
-- t.forum_id NOT IN() -- error is here
-- AND
t.approved=1
AND
(
t.moved_to='' OR t.moved_to IS NULL)
ORDER BY
t.last_post DESC
LIMIT 0,11

注意格式化会容易得多,是吗?

关于MySQL语法错误,但一切看起来都是正确的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8955325/

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