试图同时获得卡和现金会员
您好,我已经这样做了,以获取付款方式类型现金的会员详细信息
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='Cash'
AND members.member_Active LIKE 'y%'
AND (mshipstatustypes.mshipStatusType_Id='2'
OR mshipstatustypes.mshipStatusType_Id = '3'
OR mshipstatustypes.mshipStatusType_Id='6')"
,并执行另一个查询,以获取付款方式类型卡的会员详细信息
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'
AND members.member_Active LIKE 'y%'
AND (mshipstatustypes.mshipStatusType_Id='2' OR mshipstatustypes.mshipStatusType_Id = '3'
OR mshipstatustypes.mshipStatusType_Id='6')"
,但我希望具有付款方式的会员详细信息是“现金和卡”(两种类型的会员) )
任何人都可以帮助解决此查询...
我正在使用 MySQL
非常感谢........
修改后的查询
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
INNER JOIN membertomships ON membertomships.member_Id = members.member_Id
INNER JOIN mshipstatustypes ON mshipstatustypes.mshipStatusType_Id = membertomships.mshipStatusType_Id
INNER JOIN mshipoptions ON mshipoptions.mshipOption_Id = membertomships.mshipOption_Id
INNER JOIN mshiptypes ON mshiptypes.mshipType_Id = mshipoptions.mshipType_Id
WHERE membertomships.memberToMship_PayMethod IN ('Card','Card','Cheque')
AND members.member_Active LIKE 'y%'
AND ( mshipstatustypes.mshipStatusType_Id='2' OR mshipstatustypes.mshipStatusType_Id = '3'
OR mshipstatustypes.mshipStatusType_Id='6');
,但它没有显示正确的值..
嗨,但有一个问题,我有 6 名卡会员和 3 名现金会员它显示 6 和 3,但是当组合(卡和现金)时,它只会显示 4 .但必须显示(6+3)我不知道这是怎么回事哟请告诉任何解决方案。
Hi I have done like this for getting members details for payment method type cash
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='Cash'
AND members.member_Active LIKE 'y%'
AND (mshipstatustypes.mshipStatusType_Id='2'
OR mshipstatustypes.mshipStatusType_Id = '3'
OR mshipstatustypes.mshipStatusType_Id='6')"
and another query like this for getting members details with payment method type card
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'
AND members.member_Active LIKE 'y%'
AND (mshipstatustypes.mshipStatusType_Id='2' OR mshipstatustypes.mshipStatusType_Id = '3'
OR mshipstatustypes.mshipStatusType_Id='6')"
but i want the member details those who have payment methods are "cash and card" (both type members)
would any one help on this query...
i am using MySQL
Many Thanks........
Modified Query
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
INNER JOIN membertomships ON membertomships.member_Id = members.member_Id
INNER JOIN mshipstatustypes ON mshipstatustypes.mshipStatusType_Id = membertomships.mshipStatusType_Id
INNER JOIN mshipoptions ON mshipoptions.mshipOption_Id = membertomships.mshipOption_Id
INNER JOIN mshiptypes ON mshiptypes.mshipType_Id = mshipoptions.mshipType_Id
WHERE membertomships.memberToMship_PayMethod IN ('Card','Card','Cheque')
AND members.member_Active LIKE 'y%'
AND ( mshipstatustypes.mshipStatusType_Id='2' OR mshipstatustypes.mshipStatusType_Id = '3'
OR mshipstatustypes.mshipStatusType_Id='6');
but it does not showing correct values..
Hi but one problem I have six Card members and 3 cash members individually it shows 6 and three but when combining(card and cash) it will shows only 4 .but it has to be shown (6+ 3) i dont know how it was like this would yoy pls tell any solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设支付方式只有现金或银行卡,则可以省略 where 子句
membertomships.memberToMship_PayMethod='Card'
如果还有其他支付方式,则可以将其更改为
membertomships.memberToMship_PayMethod ('卡','现金')
Assuming the only payment types are cash or card, you can leave out the where clause
membertomships.memberToMship_PayMethod='Card'
If there are other payment types, you can change it to
membertomships.memberToMship_PayMethod in ('Card', 'Cash')
使用 OR 或 IN
Use OR or IN