我正在尝试在第一列中显示订单年份,在第二列中显示月份。另外,按月和按年显示总计以及总计。此外,显示消息“年度总计”和“总计”而不是空值。结果按年和月排序。
我不断收到错误消息(“字段列表”中的未知列“order_date”)有人可以帮助我吗?
select coalesce(year(order_date), 'Grand Total') as Year
, case when year(order_date) is null then ' ' else coalesce(month(order_date), 'Year Total') end as
Month
, AmntDue
, NumberOfBooksPurch
from (
select year(order_date) as Year
, month(order_date) as Month
, sum(quantity * order_price) as AmntDue
, count(order_id) as NumberOfBooksPurch
from a_bkorders.order_headers
join a_bkorders.order_details using (order_id)
group by year(order_date), month(order_date), order_id with rollup
) tbl;