-- 练习题 3.1
DROP VIEW IF EXISTS ViewPractice5_1;
CREATE VIEW ViewPractice5_1
AS
SELECT product_name, sale_price, regist_date
FROM product
WHERE sale_price >= 1000 AND regist_date = '2009-09-20';
# DROP VIEW ViewPractice5_1;
SELECT * FROM ViewPractice5_1;
-- 练习题 3.2
# INSERT INTO ViewPractice5_1 VALUES (' 刀子 ', 300, '2009-11-02');
# Field of view 'tianchi_practice.viewpractice5_1' underlying table doesn't have a default value
# 原表中定义了not null,视图插入数据时,不允许存在插入空值的情况
-- 练习题 3.3
SELECT product_id,
product_name,
product_type,
sale_price,
(SELECT AVG(sale_price)
FROM product) AS sale_price_all
FROM product;
-- 练习题 3.4
DROP VIEW IF EXISTS AvgPriceByType;
CREATE VIEW AvgPriceByType
AS
SELECT product_id,
produc