[英]SQL how do I add 3 or more conditions into the WHERE clause?
I thought by simply adding AND to the WHERE clause, I can infinitely add conditions as long as the selected columns match the WHERE clause.我想只要将 AND 添加到 WHERE 子句,我就可以无限添加条件,只要所选列与 WHERE 子句匹配即可。 However, the following query:
但是,以下查询:
No matching signature for operator AND for argument types: BOOL, BOOL, STRING.
参数类型的运算符 AND 没有匹配的签名:BOOL、BOOL、STRING。 Supported signature: BOOL AND ([BOOL, ...]) at [8:3]
支持的签名:[8:3] 处的 BOOL AND ([BOOL, ...])
SELECT
DISTINCT state,
country,
city
FROM
customer_data.customer_address
WHERE
TRIM(state) = 'OH'
AND LENGTH(country) > 2
AND SUBSTR(city,1,5)
If I were to remove the last line, it shows no error and I can run the query but why would adding another condition return such error?如果我要删除最后一行,它不会显示任何错误并且我可以运行查询但是为什么添加另一个条件会返回这样的错误?
Yes, you can combine so many logic operations with the WHERE
clause but, Your SUBSTR
is returning a string so you have to compare it with something, SQL Server in my case tries to act like `Bool so it will show the error message meaning the result is not boolean, but non-boolean:是的,您可以将如此多的逻辑操作与
WHERE
子句组合在一起,但是,您的SUBSTR
正在返回一个字符串,因此您必须将它与某些东西进行比较,SQL 在我的例子中,服务器试图像 `Bool 这样它会显示错误消息,意思是结果不是 boolean,而是非布尔值:
Msg 4145, Level 15, State 1, Line 13 An expression of non-boolean type specified in a context where a condition is expected, near ')'.
消息 4145,级别 15,State 1,第 13 行在“)”附近预期条件的上下文中指定的非布尔类型的表达式。
to fix it, you have to compare it with something, let's say the return string is equal to 'abcde'要修复它,您必须将它与某些东西进行比较,假设返回字符串等于“abcde”
here is my query using SQL Server:这是我使用 SQL 服务器的查询:
SELECT
DISTINCT state,
country,
city
FROM
tbl_Test2
WHERE
TRIM(state) = 'OH'
AND LEN(country) > 2
AND SUBSTRING(city,1,5) = 'abcde'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.