我正在尝试从表中获取数据,如代码所示。而不是ThisYear和LastYear;我想根据当前年份显示年份编号。我想尝试使用"年(curdate())"和"年(curdate()) - 1&#34 ;;和列标题将是2017年和2016年,而不是ThisYear和LastYear。
SELECT Months AS Months,
SUM(if(Years = Year(curdate()) AS ThisYear,
SUM(if(Years = Year(curdate())-1, in_amount, null)) AS LastYear,
FIELD(Months, 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December') AS `FIELD(Months, 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')` FROM ao_vw_revenue GROUP BY Months ORDER BY FIELD(Months, 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')
有任何帮助吗?感谢。