本文介绍了从当前日期sql减去月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试减去今天(从1个月前到永远报告)的日期.到目前为止,我已经尝试过
I am trying to substract dates from today (Get a 1 month ago till forever report). So far I've tried
DATE_SUB(NOW(), INTERVAL 1 MONTH)
这里是上下文:
SELECT contracts.currency , ROUND(SUM(
CASE
WHEN contracts.currency = 'USD' THEN contracts.value*550
WHEN contracts.currency = 'UF' THEN contracts.value*22000
ELSE contracts.value
END),2)
AS real_value
FROM contracts
WHERE currency IN ('USD','UF','CLP') AND date >=DATE_SUB(NOW(), INTERVAL 1 MONTH)
GROUP BY currency
ORDER BY currency ASC
推荐答案
看看是否有帮助:
SELECT contracts.currency , ROUND(SUM(
CASE contracts.currency
WHEN 'USD' THEN contracts.value*550
WHEN 'UF' THEN contracts.value*22000
ELSE contracts.value
END),2)
AS real_value
FROM contracts
WHERE currency IN ('USD','UF','CLP') AND
date >=DATE_SUB(curdate(), INTERVAL 1 MONTH) AND
date <=curdate()
GROUP BY currency
ORDER BY currency ASC
如果不是,最好检查表中日期"列的类型.有时是varchar而不是date.这是为了防止您不是创建表的人.
If not, it would be nice to check the type of the column "date" in table. Sometimes it is varchar instead of date. This is in case you are not the one who has created the table.
这篇关于从当前日期sql减去月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!