《SQL基础教程第2版》Chap.5练习题
-- where 子句中有多个条件
create view ViewPractice5_1
as
select product_name, sale_price, regist_date
from Product
where sale_price >= 1000
and regist_date = '2018-12-10'
5-2
向视图 ViewPractice5_1 插入数据.
insert into ViewPractice5_1 values ('knife', 300, '2019-1-21');
❓为什么SQL执行错误.
5-3
-- 执行错误
select product_id, product_name, product_type, sale_price,
avg(sale_price) as 'sale_price_all'
from Product;
-- 标量子查询(本质是,将返回的结果作为外层子句的常量)
select product_id, product_name, product_type, sale_price,
(select avg(sale_price) from Product) as 'sale_price_all'
from Product;
5-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 P1.product_type) as 'avg_sale_price'
from Product P1;