解答例 - 実習課題1 - 9. ビュー
実習課題 1
8章実習課題 1 で作成した SQL 文をもとに、ビューを作成しなさい。
- ビュー名は MonthCarsListView とする。
select * from MonthCarsListView;としたときに、8章実習課題 1 の結果と同じになるようにすればよい。
解答例
CREATE VIEW MonthCarsListView AS
SELECT month AS 月, count(*) AS 売上台数
FROM (
SELECT '1月' as month
FROM accept_order
WHERE accept_date BETWEEN '20010101' AND '20010131'
UNION ALL SELECT '2月' as month
FROM accept_order
WHERE accept_date BETWEEN '20010201' AND '20010228'
UNION ALL SELECT '3月' as month
FROM accept_order
WHERE accept_date BETWEEN '20010301' AND '20010331'
) month_table
GROUP BY month;

