gpt4 book ai didi

mysql - 无论条件如何都检索所有详细信息

转载 作者:行者123 更新时间:2023-11-29 09:07:31 25 4
gpt4 key购买 nike

您好,我有一个查询,将检索支付方式类型为现金且 memberstatustype 的 id 为 2 、 3 、 6 的成员(member)。当成员(member)的付款方式类型为现金、dd 和卡时,查询工作正常,但它将检索没有付款方式为卡的成员(member)的所有详细信息,这是我的查询

SELECT members.member_Id, members.member_Lastname, members.member_Firstname, members.member_PostCode,members.member_Reference,  members.member_Dob,30*memberToMship_ChargePerPeriod/DateDiff(memberToMship_EndDate, memberToMship_StartDate) As monthly_amount, mshiptypes.mshipType_Name, mshipstatustypes.mshipStatusType_Name,membertomships.memberToMship_EndDate,IF(mshipOption_Period='year', TIMESTAMPDIFF (YEAR,memberToMship_StartDate, memberToMship_EndDate),  TIMESTAMPDIFF (MONTH ,memberToMship_StartDate,memberToMship_EndDate ) ) *memberToMship_ChargePerPeriod As Total 
FROM members
LEFT JOIN membertomships ON membertomships.member_Id = members.member_Id
LEFT JOIN mshipstatustypes ON mshipstatustypes.mshipStatusType_Id = membertomships.mshipStatusType_Id
LEFT JOIN mshipoptions ON mshipoptions.mshipOption_Id = membertomships.mshipOption_Id
LEFT JOIN mshiptypes ON mshiptypes.mshipType_Id = mshipoptions.mshipType_Id
WHERE
membertomships.memberToMship_PayMethod='Card' OR mshipstatustypes.mshipStatusType_Id='2' OR mshipstatustypes.mshipStatusType_Id = '3' OR mshipstatustypes.mshipStatusType_Id='6';

任何人都可以帮我解决这个问题吗....我在“或”条件下做错了什么吗

最佳答案

您的 WHERE 子句需要如下所示:

WHERE membertomships.memberToMship_PayMethod='Card' 
AND (mshipstatustypes.mshipStatusType_Id='2'
OR mshipstatustypes.mshipStatusType_Id = '3'
OR mshipstatustypes.mshipStatusType_Id='6');

您的原始查询会查找具有以下任一条件的人员:

  • membertomships.memberToMship_PayMethod='卡'
  • mshipstatustypes.mshipStatusType_Id='2'
  • mshipstatustypes.mshipStatusType_Id='3'
  • mshipstatustypes.mshipStatusType_Id='6'

你想要的是拥有这些能力的人

  • membertomships.memberToMship_PayMethod='卡'

以及以下其中一项:

  • mshipstatustypes.mshipStatusType_Id='2'
  • mshipstatustypes.mshipStatusType_Id='3'
  • mshipstatustypes.mshipStatusType_Id='6'

关于mysql - 无论条件如何都检索所有详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6649398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com