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

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


谁能帮我找出原因:除了正确的会员记录,我还要得到那些MemShrBal大于250.0并且MemDOB低于'1973'的成员记录?

最佳答案

您需要一些括号:

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

10-01 23:38