我正在尝试从今天减去日期(获取1个月前直到永远报告)。到目前为止,已经尝试了
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
答案 0 :(得分:0)
看看这是否有帮助:
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。如果您不是创建该表的人。