输出中的无关结果? [英] Unrelated result in the output?

查看:28
本文介绍了输出中的无关结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的查询:

SELECT TOP 10000 [Service_order]
      ,[COMPANY]
      ,[PENDING_DAYS]
      ,[SERVICE_TYPE]
      ,[SERVICE_TYPE_TXT]
      ,[STATUS]
      ,[STATUS_TEXT]
      ,[REASON]
      ,[REASON_TEXT]
      ,[ASC code]
      ,[ASC name]
      ,[MODEL]
      ,[INOUTWTY]
      ,[Part_code1]
      ,[PS1]
      ,[confirmation_No1]
      ,[Part_code2]
      ,[PS2]
      ,[SO_NO2]
      ,[Part_code3]
      ,[PS3]
      ,[SO_NO3]
      ,[Part_code4]
      ,[PS4]
      ,[SO_NO4]
      ,[Part_code5]
      ,[PS5]
      ,[SO_NO5]
      ,[Engineer name]
  FROM ['NewLP']
where REASON_TEXT = 'Parts Not available (ASC)'
or  REASON_TEXT = 'Parts In Transit (Samsung)'
or REASON_TEXT = 'Parts Back Ordered (Samsung)'
  and PS1 = 'U' 
  and PS2 = 'U' or PS2 = ''
  and PS3 = 'U' or PS3 = ''
  and PS4 = 'U' or PS4 = ''
  and PS5 = 'U' or PS5 = ''

我不知道到底哪个部分是错误的,但是原因文本应该是条件中的那些,第一个 ps 应该是U",其余的应该是U"或空,但是当我运行查询时,结果是不应该是什么.结果如下:

I don't know which part is wrong exactly but the reason_text should be those in the condition and first ps should be 'U' and the rest should be 'U' or empty, but when I run the query the result is not what it should be. here is the results:

当我在条件中使用其中一个原因文本时,只有前两个 PS 正确显示,其余(PS3、PS4、PS5)不符合条件?

And when I use one of the reason_text in the condition only first two PS's show correctly, the rest(PS3,PS4,PS5) is not following the condition?

这是我使用其中一个 reason_Text 时的结果,我只选择了重要的列.

here is the result when I use one of the reason_Text, I only selected the columns that are important.

我将不胜感激.

推荐答案

You need to put your PS* and REASON TEXT where using OR> 将条件放入括号中,如下所示:

You need to put your PS* and REASON TEXT where using OR conditions into brackets like this:

where (
      REASON_TEXT = 'Parts Not available (ASC)'
or    REASON_TEXT = 'Parts In Transit (Samsung)'
or    REASON_TEXT = 'Parts Back Ordered (Samsung)'
      )
and   PS1 = 'U' 
and   ( PS2 = 'U' or PS2 = '' )
and   ( PS3 = 'U' or PS3 = '' )
and   ( PS4 = 'U' or PS4 = '' )
and   ( PS5 = 'U' or PS5 = '' )

请记住,AND 运算符优先于 OR,并且在组合这些条件时,使用括号很重要,以便数据库知道评估每个条件的顺序.

Remember that AND operator has precedence over OR and when combining these conditions, it is important to use parentheses so that the database knows in which order to evaluate each condition.

完整查询

SELECT TOP 10000 [Service_order]
      ,[COMPANY]
      ,[PENDING_DAYS]
      ,[SERVICE_TYPE]
      ,[SERVICE_TYPE_TXT]
      ,[STATUS]
      ,[STATUS_TEXT]
      ,[REASON]
      ,[REASON_TEXT]
      ,[ASC code]
      ,[ASC name]
      ,[MODEL]
      ,[INOUTWTY]
      ,[Part_code1]
      ,[PS1]
      ,[confirmation_No1]
      ,[Part_code2]
      ,[PS2]
      ,[SO_NO2]
      ,[Part_code3]
      ,[PS3]
      ,[SO_NO3]
      ,[Part_code4]
      ,[PS4]
      ,[SO_NO4]
      ,[Part_code5]
      ,[PS5]
      ,[SO_NO5]
      ,[Engineer name]
  FROM ['NewLP']
  where (
        REASON_TEXT = 'Parts Not available (ASC)'
  or    REASON_TEXT = 'Parts In Transit (Samsung)'
  or    REASON_TEXT = 'Parts Back Ordered (Samsung)'
        )
  and   PS1 = 'U' 
  and   ( PS2 = 'U' or PS2 = '' )
  and   ( PS3 = 'U' or PS3 = '' )
  and   ( PS4 = 'U' or PS4 = '' )
  and   ( PS5 = 'U' or PS5 = '' )

这篇关于输出中的无关结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆