“foo”在哪里?或“酒吧”并且“哈哈”或“rofl” MySQL

发布于 2024-10-04 08:14:41 字数 94 浏览 3 评论 0原文

将以什么顺序对其进行评估。我的意图是,如果它找到 foo 或 bar,它也会搜索 lol 和 rofl。
这完全是在树林里吗?如果是这样,人们将如何评估这样的表达式。

In what order would this be evaluated. My intension is that if it finds either foo or bar, it would also search for lol and rofl.
Is this totally in the woods? And if so, how would one evaluate an expression like that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

念﹏祤嫣 2024-10-11 08:14:41

AND 运算符的优先级高于 < code>OR 在 MySql 中,因此当前表达式的计算结果为:

WHERE 'foo' OR ('bar' AND 'lol') OR 'rofl'

如果要强制计算顺序,请在表达式中添加括号:

WHERE ('foo' OR 'bar') AND ('lol' OR 'rofl')

The AND operator has higher precedence than OR in MySql, so your current expression evaluates as:

WHERE 'foo' OR ('bar' AND 'lol') OR 'rofl'

Add parentheses to the expression if you want to force the evaluation order:

WHERE ('foo' OR 'bar') AND ('lol' OR 'rofl')
情愿 2024-10-11 08:14:41

首先处理AND,然后处理OR。所以,它将是:

'foo' OR ('bar' AND 'lol') OR 'rofl'

之后,它是从左到右的顺序。

AND will be processed first, after that OR will be processed. So, it will be:

'foo' OR ('bar' AND 'lol') OR 'rofl'

After that, it is left to right order.

谜兔 2024-10-11 08:14:41

看一下文档 - 并且有更高的优先级,所以它会是这样的:

WHERE 'foo' OR ( 'bar' AND 'lol' ) OR 'rofl'

take a look at the documentation - AND has a higher precedence, so it would be like this:

WHERE 'foo' OR ( 'bar' AND 'lol' ) OR 'rofl'
您的好友蓝忘机已上羡 2024-10-11 08:14:41
SELECT
  Id, Name
FROM
  TestTable
WHERE
    (Name = 'foo') OR (Name = 'bar') AND (Name = 'lol') OR (Name = 'rofl')

将在 MS SQL Server 中为您提供以下结果:

1 foo
4 rofl

因此,它似乎将结合 bar AND lol 并分别评估 foo 和 rofl,如下所示:

SELECT
      Id, Name
    FROM
      TestTable
    WHERE
        (Name = 'foo') OR ((Name = 'bar') AND (Name = 'lol')) OR (Name = 'rofl')

您可能想要做的是(技术上):

SELECT
      Id, Name
    FROM
      TestTable
    WHERE
        ((Name = 'foo') OR (Name = 'bar')) AND ((Name = 'lol') OR (Name = 'rofl'))
SELECT
  Id, Name
FROM
  TestTable
WHERE
    (Name = 'foo') OR (Name = 'bar') AND (Name = 'lol') OR (Name = 'rofl')

Will give you the following result in MS SQL Server:

1 foo
4 rofl

So it seems it will combine bar AND lol and evals foo and rofl seperately like this:

SELECT
      Id, Name
    FROM
      TestTable
    WHERE
        (Name = 'foo') OR ((Name = 'bar') AND (Name = 'lol')) OR (Name = 'rofl')

What you probably want to do is (technically):

SELECT
      Id, Name
    FROM
      TestTable
    WHERE
        ((Name = 'foo') OR (Name = 'bar')) AND ((Name = 'lol') OR (Name = 'rofl'))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文