sql查询claus

发布于 2025-01-22 13:27:08 字数 267 浏览 2 评论 0原文

我有这个条款的

WHERE        (ACCDAT_0 >= '2020-01-01 00:00:00.000')and STA_0='3'
and
(NUM_0 LIKE '%FTC%') OR (NUM_0 LIKE '%NCC%') OR (NUM_0 LIKE '%DCF%')

重点是,如果sta_0 ='1'出现在查询中,因为它就像NCC一样,除了标志为1的ncc以外,所有NCC都可以出现所有NCC吗?

I have this where clause

WHERE        (ACCDAT_0 >= '2020-01-01 00:00:00.000')and STA_0='3'
and
(NUM_0 LIKE '%FTC%') OR (NUM_0 LIKE '%NCC%') OR (NUM_0 LIKE '%DCF%')

The point is that if STA_0='1' is appearing in the query because its like NCC it possible to appear all NCC except the ones where the flag is 1?

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

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

发布评论

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

评论(1

给不了的爱 2025-01-29 13:27:08

这确实是一个评论,但是它太大了,无法适合评论空间...对我上面的评论进行了详细说明。

“或”是一个低优先级操作员,这意味着它在所有毕竟都会进行评估。这意味着您的查询是这样做的:

WHERE
 (ACCDAT_0 >= '2020-01-01 00:00:00.000' and
  STA_0='3' and
  NUM_0 LIKE '%FTC%') OR NUM_0 LIKE '%NCC%' OR NUM_0 LIKE '%DCF%'
  

意味着如果num_0就像ncc或dcf一样,则忽略了前两个条件。那可能不是您的意思,但这就是您所说的。

您可能意味着这个问题:

WHERE
  ACCDAT_0 >= '2020-01-01 00:00:00.000' and
  STA_0='3' and
 (NUM_0 LIKE '%FTC%' OR NUM_0 LIKE '%NCC%' OR NUM_0 LIKE '%DCF%')

更大的教训是……如果您混合使用,并且,或者,请确保使用括号,以便它确实做到了您的意思。

This is really a comment, but it's too large to fit in the comment space... elaboration on my comment above.

"OR" is a low precedence operator, meaning it is evaluated after all "AND." What this means is your query is doing this:

WHERE
 (ACCDAT_0 >= '2020-01-01 00:00:00.000' and
  STA_0='3' and
  NUM_0 LIKE '%FTC%') OR NUM_0 LIKE '%NCC%' OR NUM_0 LIKE '%DCF%'
  

Meaning if NUM_0 is like NCC or DCF, then the first two criteria are ignored. That may not be what you meant, but that's what you said.

You might have meant this:

WHERE
  ACCDAT_0 >= '2020-01-01 00:00:00.000' and
  STA_0='3' and
 (NUM_0 LIKE '%FTC%' OR NUM_0 LIKE '%NCC%' OR NUM_0 LIKE '%DCF%')

And the larger lesson is... if you mix AND and OR, be sure to use parentheses so it does exactly what you mean.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文