这是实际的查询
Select members.member_Id, membertomships.memberToMship_DueDay, sum(memberToMship_ChargePerPeriod)-sum(memberAccTran_Value) as StillDue
from membertomships
left join mshipoptions on membertomships.mshipOption_Id = mshipoptions.mshipOption_Id
left join members on membertomships.member_Id = members.member_Id
left join memberacctrans on memberacctrans.member_Id = members.member_Id
WHERE sum(if(memberToMship_DueDay<CURDATE(),0,memberToMship_ChargePerPeriod))>sum(memberAccTran_Value);
修改查询:
Select
members.member_Id,
membertomships.memberToMship_DueDay,
sum(sum(memberToMship_InductionFee+memberToMship_JoinFee + (IF(mshipOption_Period='year', TIMESTAMPDIFF (YEAR ,memberToMship_StartDate, memberToMship_EndDate), TIMESTAMPDIFF (MONTH ,memberToMship_StartDate, memberToMship_EndDate)) * memberToMship_ChargePerPeriod))) - sum(memberAccTran_Value) as StillDue
from membertomships
left join mshipoptions on membertomships.mshipOption_Id = mshipoptions.mshipOption_Id
left join members on membertomships.member_Id = members.member_Id
left join memberacctrans on memberacctrans.member_Id = members.member_Id
group by member_Id
having sum(if(memberToMship_DueDay<today(),0,memberToMship_ChargePerPeriod))>sum(memberAccTran_Value);
注意:paymenttable = memberacctrans 表
得到这样的错误
Error Code: 1111
Invalid use of group function
有人能帮我解决这个问题吗