一、作业答案
CHR003
3.1
CREATE VIEW ViewPractice5_1(product_name, sale_price, regist_date)
AS
SELECT product_name, sale_price, regist_date
FROM product
WHERE product.sale_price>=1000 AND regist_date='2009-09-20';
3.3
SELECT product_id,product_name, product_type, sale_price, (SELECT AVG(sale_price) FROM product) AS avg_price
FROM product ;
3.4
SELECT
product_id,
product_name,
product_type,
sale_price,(
SELECT
avg(sale_price)
FROM
product AS p2
WHERE
p1.product_type = p2.product_type
GROUP BY
product_type
) AS avg_sale_price
FROM
product AS p1
3.5 不会,系统会自动去除null
3.6
(1)会展示购买价格不是500、2800、5000的产品
(2)直接展示null值了,想排除null,应该用is not null.
3.7
SELECT COUNT(case when sale_price<1000 then product_name else NULL END) as low_price,
COUNT(case when sale_price<3000 AND sale_price>1001 then product_name else NULL END) as mid_price,
COUNT(case when sale_price>3001 then product_name else NULL END) as high_price
from product;
二、关于语法的逻辑有的时候还是有些迷糊,需多思考多加练习,再次复习顺序“FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY。”。但是最近逐渐get新技能的感觉还是有些成就感哒,哈哈哈~后面的课程感觉难度也是越来越大了,需要花更多的时间学习与思考了,加油!