2

我想通过我的Membership表查询某些成员的结果,但我得到了错误的结果。这是我的查询:

  select MemNo, MemDOB, MemberType, MemShrBal
  From Membership
  Where MemberType = 1 or MemberType = 2 
  and MemDOB > '1973/12/31' 
  and MemShrBal = 250.00

谁能帮我找出原因:除了正确的会员记录外,我还获得了超过 250.0 及以下“1973”的会员记录?MemShrBalMemDOB

4

1 回答 1

9

你需要一些括号:

select MemNo, MemDOB, MemberType, MemShrBal
  From Membership
  Where (MemberType = 1 or MemberType = 2)
  and MemDOB > '1973/12/31' 
  and MemShrBal = 250.00

and比 绑定得更紧or,所以没有括号,它是

  MemberType = 1

  or
      MemberType = 2
      and MemDOB > '1973/12/31' 
      and MemShrBal = 250.00
于 2013-08-21T07:09:45.770 回答