如何添加datediff和更新表?

wa7juj8i  于 2021-08-09  发布在  Java
关注(0)|答案(0)|浏览(169)

目前我正在和 DATEDIFF . 详情如下:
表db1:id、update\u time、expire\u time、total\u diff
表db2:id,用户名

SELECT  db2.ID AS ID,
        updatetime.update_time AS Latest_Payment,
        expiretime.expire_time AS Payment_Till
FROM    db2
INNER JOIN db1 ON db2.ID = db1.user_id
LEFT JOIN db1 updatetime ON db2.ID = updatetime.user_id AND updatetime.update_time
LEFT JOIN db1 expiretime ON db2.ID = expiretime.user_id AND expiretime.expire_time
WHERE db2.id >= '0' AND expiretime.expire_time < NOW()
GROUP BY db2.ID;

我想补充一下 DATEDIFF(month, CURRENT_TIMESTAMP, updatetime.update_time) 上面的代码,但没有得到运气。
我要做的是显示一个包含以下内容的表:

1. Latest Payment
2. Payment Till
3. Total Diff (How many months payment due)*$80

此时我只能显示“最新付款”和“付款截止日期”。我可以知道如何添加datediff,它将在1个表中显示它吗?
我试图获得的数据/表格示例:

Name     | Latest Payment (updatetime) | Subscribe Till (expiretime) | Month Due X $80

Arby     | 21/3/2020                   | 21/4/2020      | 80

Casi     | 21/2/2020                   | 21/5/2020      | 0

Will     | 21/2/2020                   | 21/4/2020      | 160

非常感谢你的帮助。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题