gpt4 book ai didi

MySQL语法错误[Left Join]

转载 作者:行者123 更新时间:2023-11-29 18:31:16 26 4
gpt4 key购买 nike

所以我在下面得到了这个查询,它给了我一个语法错误。我将在查询下方显示错误。

请检查以下内容:

SELECT g.fullname, g.id as guardian_id, g.email, g.email_2, s.title, s.domain, d.device_id as device, d.os, gf.booking_open_notified, gf.days_notified_7, gf.days_notified_3, gf.day_notified, s.id as school_id, p.firstname, p.surname 
FROM guardian as g
LEFT JOIN guardian_form as gf ON gf.school_id = g.school_id
LEFT JOIN school as s ON s.id = g.school_id
LEFT JOIN school_design as sd ON sd.school_id = s.id
LEFT JOIN device as d ON d.school_id = s.id AND d.guardian_id = g.id
(
LEFT JOIN pupil as p ON p.school_id = s.id AND
(
p.grade_id = gf.grade_id
OR p.grade_id = gf.grade_id_2
OR p.grade_id = gf.grade_id_3
OR p.grade_id = gf.grade_id_4
OR p.grade_id = gf.grade_id_5
OR p.grade_id = gf.grade_id_6
OR p.grade_id = gf.grade_id_7
OR p.grade_id = gf.grade_id_8
OR p.grade_id = gf.grade_id_9
OR p.grade_id = gf.grade_id_10
)
) OR (
LEFT JOIN guardian_form_group as gfg ON gfg.guardian_form_id = gf.id
LEFT JOIN pupil_group as pg ON pg.group_id = gfg.group_id
LEFT JOIN pupil as p ON p.id = pg.pupil_id AND pg.school_id = s.id
)
WHERE (
gf.booking_open_notified != 1
OR gf.days_notified_7 != 1
OR gf.days_notified_3 != 1
OR gf.day_notified != 1
)
AND gf.active = 1
AND sd.disable_parents_evening_notification_and_email = 0
GROUP BY gf.id, p.id
LIMIT 20

错误:

Error SQL query: Documentation

SELECT g.fullname, g.id as guardian_id, g.email, g.email_2, s.title,
s.domain, d.device_id as device, d.os, gf.booking_open_notified,
gf.days_notified_7, gf.days_notified_3, gf.day_notified, s.id as
school_id, p.firstname, p.surname FROM guardian as g LEFT JOIN
guardian_form as gf ON gf.school_id = g.school_id LEFT JOIN school as
s ON s.id = g.school_id LEFT JOIN school_design as sd ON sd.school_id
= s.id LEFT JOIN device as d ON d.school_id = s.id AND d.guardian_id = g.id
(
LEFT JOIN pupil as p ON p.school_id = s.id AND
(
p.grade_id = gf.grade_id
OR p.grade_id = gf.grade_id_2
OR p.grade_id = gf.grade_id_3
OR p.grade_id = gf.grade_id_4
OR p.grade_id = gf.grade_id_5
OR p.grade_id = gf.grade_id_6
OR p.grade_id = gf.grade_id_7
OR p.grade_id = gf.grade_id_8
OR p.grade_id = gf.grade_id_9
OR p.grade_id = gf.grade_id_10
)
) OR

MySQL said: Documentation

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

'JOIN pupil as p ON p.school_id = s.id AND 
(
p.grade_id = gf.' at line 8

最佳答案

你的语法就像

SELECT listOfColumns FROM table1 LEFT JOIN table2 (LEFT JOIN table3) OR (LEFT JOIN table4)

您为什么尝试使用“OR”来加入?不支持此操作。如果您想过滤掉表格,请尝试改进您的 ON 条件

关于MySQL语法错误[Left Join],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45670668/

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