最初の列に注文の年、2 番目の列に月を示す本の注文データを表示しようとしています。さらに、月ごと、年ごとの合計と総合計を表示します。また、null の代わりに「Yearly Total」と「Grand Total」というメッセージを表示します。結果は年月順にソートされます。
エラーが表示され続けます (「フィールド リスト」の不明な列「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;