gpt4 book ai didi

mysql - SQL如何在NOT IN中使用很多语句

转载 作者:行者123 更新时间:2023-11-29 01:35:07 26 4
gpt4 key购买 nike

我尝试执行这个查询:

SELECT ISBN FROM table2 WHERE 
NOT IN ISBN=('8426429807','840149768X')
group by ISBN
ORDER BY AVG(`Book-Rating`) DESC LIMIT 10

但是我得到这个形状的错误

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IN ISBN=('8426429807','840149768X')

如何在 Not In 中使用多个 isbn

最佳答案

Not In()语法是:

expr NOT IN (value,...)

基本上,列/表达式应该位于 Not In 之前,并且您不使用 = 运算符。应该是:

SELECT ISBN
FROM table2
WHERE ISBN NOT IN ('8426429807',
'840149768X')
GROUP BY ISBN
ORDER BY AVG(`Book-Rating`) DESC
LIMIT 10

另一种编写相同查询的方法是使用 NOT (expr IN (value, ...)):

SELECT ISBN
FROM table2
WHERE NOT (ISBN IN ('8426429807',
'840149768X'))
GROUP BY ISBN
ORDER BY AVG(`Book-Rating`) DESC
LIMIT 10

关于mysql - SQL如何在NOT IN中使用很多语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52926454/

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