[英]my AND isn't working again, it isn't only showing what I want it to equal
So I had similar questions and it was answered, but this time I have the parenthesis in the right places and my last AND function isn't properly working, the property_type is showing other results than just "sidewalk".所以我有类似的问题并且得到了回答,但是这次我的括号在正确的位置,而我的最后一个 AND function 无法正常工作,property_type 显示的结果不仅仅是“人行道”。
SELECT
footprint_length,number_of_docks , property_type, station_id
FROM
bigquery-public-data.austin_bikeshare.bikeshare_stations
WHERE
footprint_length > 45
AND (number_of_docks BETWEEN 1 AND 17) OR (number_of_docks = 19)
AND property_type = "sidewalk"
Your current criteria is equivalent to:您当前的标准相当于:
(
footprint_length > 45 AND
number_of_docks BETWEEN 1 AND 17 AND
property_type = "sidewalk"
)
OR
number_of_docks = 19
In other words OR number_of_docks=19
applies even if footprint_length <=45!换句话说,即使footprint_length <=45,
OR number_of_docks=19
也适用!
Did you want:你想要:
footprint_length > 45 AND
property_type = "sidewalk" AND
(
(number_of_docks BETWEEN 1 AND 17)
OR
number_of_docks = 19
)
?? ??
If your goal is to show cases where the number of docks is between 1 and 17 or 19, I would delete the closed parenthesis after 17 and the open one before "number".如果您的目标是显示码头数量在 1 到 17 或 19 之间的情况,我会删除 17 之后的右括号和“数字”之前的开括号。
AND (number_of_docks BETWEEN 1 AND 17 OR number_of_docks = 19)
Currently, if number_of_docks=19 evaluates to true, the whole condition will probably show true.目前,如果 number_of_docks=19 评估为真,则整个条件可能会显示为真。
Perhaps more simply, you could avoid the OR and parenthesis altogether and just change your range to 1-19 and then weed out 18 since that is effectively what you're doing anyway with the OR.也许更简单地说,您可以完全避免 OR 和括号,只需将您的范围更改为 1-19,然后清除 18,因为这实际上是您对 OR 所做的事情。 AND is usually a little easier to manage in my opinion.
在我看来,AND 通常更容易管理。
AND number_of_docks BETWEEN 1 AND 19 AND number_of_docks != 18 AND property_type='sidewalk'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.