gpt4 book ai didi

mysql - 使用mysql查询计算截至提及日期的总金额

转载 作者:行者123 更新时间:2023-11-29 00:54:49 24 4
gpt4 key购买 nike

                   membership table
membership start date 2011-01-10
membership end date 2012-09-08
membership monthly amount £120.00
member_Id

member table
member_id

成员(member)将在每个月的 10 日付款...我可以得到成员(member)截至 2011 年 5 月 15 日这一天支付的总金额吗?是否可以使用 mysql 查询。

这是sql查询你们推荐的

                    SELECT TIMESTAMPDIFF(MONTH, membertomships.memberToMship_StartDate, MIN(membertomships.memberToMship_EndDate,'2011-7-06'))* memberToMship_ChargePerPeriod FROM membertomships WHERE membertomships.member_Id = '1';

但它在 memberToMship_EndDate,'2011-7-06' 日期 memberToMship_EndDate 和这个日期 '2011-7-06' 之间给出错误

你能解释一下为什么会报错吗

最佳答案

SELECT TIMESTAMPDIFF(MONTH, start_date, MIN(end_date,'2011-05-15')) * amount from membership where membershipId=@memberdshipId

还包括当前日期......

 SELECT TIMESTAMPDIFF(MONTH, start_date, MIN(end_date,'2011-05-15')) * amount ,TIMESTAMPDIFF(MONTH, start_date, MIN(end_date,CURDATE())) * amount from membership where membershipId=@memberdshipId

这对我来说在 ms sqlserver 中工作正常,请更改为 mysql syntex

select datediff(Month,startdate,enddate)*amount as Enddateamount,
datediff(Month,startdate,'12/6/2010')*amount as amountongivendate,
datediff(Month,startdate,getdate())*amount as amounttoday
from membership

sql server screen shot

关于mysql - 使用mysql查询计算截至提及日期的总金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6594028/

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