不确定如何在MySQL查询的if / else语句中输出日期。
这是我的选择声明:
SELECT MONTH(Max(a.planned_date)) AS MONTH,
a.planned_date AS DATE,
YEAR(Max(a.planned_date)) AS YEAR,
Sum(IF(MONTH(a.planned_date) = 1, b.VALUE, 0)) AS Jan,
Sum(IF(MONTH(a.planned_date) = 2, b.VALUE, 0)) AS Feb,
Sum(b.VALUE) AS total
FROM b
INNER JOIN a
ON b.id = a.id
INNER JOIN c
ON b.reg_id = c.reg_id
WHERE YEAR(a.planned_date) < DATE(Now())
GROUP BY c.reg_id
我所要做的就是拥有一个Jan到Dec的交叉表,但是返回一个MAX日期来带来价值。但是,我这样做的方式是价值加倍。
请帮助您的建议。
谢谢