您可以使用 SQL GROUP BY 子句按年份对结果进行分组,并使用 SUM 函数计算每年每个类别的总费用。
SELECT Year,
SUM(Transportation) AS Total_Transportation,
SUM(Meals) AS Total_Meals,
SUM(Park) AS Total_Park,
SUM(Total) AS Grand_Total
FROM ExpensesTable
GROUP BY Year;
SQL 小提琴代码 单击此处查看您想要的内容。