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,memberTo开发者_高级运维Mship_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.
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')
Use OR or IN
WHERE membertomships.memberToMship_PayMethod IN ('Card','Cash')
WHERE (membertomships.memberToMship_PayMethod ='Card' OR membertomships.memberToMship_PayMethod ='Cash')
精彩评论