gpt4 book ai didi

mysql - 2 查询单独运行良好,但组合起来会产生语法错误

转载 作者:行者123 更新时间:2023-11-29 16:35:32 25 4
gpt4 key购买 nike

第一个查询涉及与特定主题相关的书籍和作者列表,并生成正确的结果:

SELECT BOOK_NUM,
BOOK_TITLE,
BOOK_SUBJECT,
AU_LNAME
FROM BOOK
JOIN WRITES USING (BOOK_NUM)
JOIN AUTHOR USING (AU_ID)
WHERE BOOK_SUBJECT = 'CLOUD'
ORDER BY BOOK_TITLE;

第二个扩展了主题并产生了正确的结果:

SELECT BOOK_NUM,
BOOK_TITLE,
BOOK_SUBJECT,
AU_FNAME,
AU_LNAME,
Count(BOOK_TITLE) AS `NUM BOOKS BY AUTHOR`
FROM BOOK
JOIN WRITES USING (BOOK_NUM)
JOIN AUTHOR USING (AU_ID)
GROUP BY BOOK_NUM, AU_ID
ORDER BY `NUM BOOKS BY AUTHOR`,
AU_LNAME;

当我将两者结合起来时,它会在 WHERE BOOK_SUBJECT = 'CLOUD': 处产生语法错误:

SELECT BOOK_NUM,
BOOK_TITLE,
BOOK_SUBJECT,
AU_FNAME,
AU_LNAME,
Count(BOOK_TITLE) AS `NUM BOOKS BY AUTHOR`
FROM BOOK
JOIN WRITES USING (BOOK_NUM)
JOIN AUTHOR USING (AU_ID)
GROUP BY BOOK_NUM, AU_ID
WHERE BOOK_SUBJECT = 'CLOUD'
ORDER BY `NUM BOOKS BY AUTHOR`,
AU_LNAME,
BOOK_TITLE;

无论我把它放在哪里,我都会遇到相同的错误,如果删除它,代码就会运行。我需要做什么来解决这个问题?我需要包含这个 where 子句。预先感谢您帮助我。

最佳答案

好问题。尝试引用一些有关表达式顺序的文档...

尝试以下代码,我们在其中适当移动了 WHERE 语句。

SELECT 
BOOK_NUM,
BOOK_TITLE,
BOOK_SUBJECT,
AU_FNAME,
AU_LNAME,
Count(BOOK_TITLE) AS `NUM BOOKS BY AUTHOR`

FROM BOOK
JOIN WRITES USING (BOOK_NUM)
JOIN AUTHOR USING (AU_ID)

WHERE BOOK_SUBJECT = 'CLOUD'

GROUP BY BOOK_NUM, AU_ID

ORDER BY `NUM BOOKS BY AUTHOR`,
AU_LNAME,
BOOK_TITLE;

关于mysql - 2 查询单独运行良好,但组合起来会产生语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53618177/

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