我有代码,想添加条件WHERE YEAR(reg_date)= YEAR(CURDATE()) 我需要这段代码花费今年的一个月,也许可以用另一种方式来完成。
我尝试了
4)我将MONTH(DATE(Table11.reg_date))= MONTH(CURDATE())更改为 YEAR_MONTH(DATE(Table11.reg_date))= YEAR_MONTH(CURDATE())。然后我 读到它不能以这种方式工作。
SELECT
Doh1.MONTHSUM - Table11.MONTHSUM AS MONTH_PROFIT
FROM (SELECT
SUM(CASE WHEN MONTH(DATE(Doh.reg_date)) = MONTH(CURDATE()) THEN
(COALESCE
(Doh.first,0)+Doh.second) ELSE 0 END) AS MONTHSUM
FROM Doh) AS Doh1,
(SELECT
SUM(CASE WHEN MONTH(DATE(Table11.reg_date)) = MONTH(CURDATE()) THEN
Table.first ELSE 0 END) AS MONTHSUM
FROM Table) AS Table11