sql练习day03

#3.1
CREATE VIEW ViewPractices5_1 (product_name,sale_price,regist_date)
AS
SELECT product_name,sale_price,regist_date
FROM product
WHERE sale_price>= 1000
AND regist_date=‘2009-09-20’;
SELECT * FROM ViewPractices5_1;

#3.2
INSERT INTO ViewPractices5_1 VALUES(‘刀子’,3000,‘2009-11-02’);
UPDATE ViewPractices5_1
SELECT * FROM ViewPractices5_1;

#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
CREATE VIEW AvgPriceByType (product_id,product_name,product_type,sale_price,avg_sale_price)
AS
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的时候,结果的确会变成null

#3.6
SELECT product_name,purchase_price
FROM product
WHERE purchase_price NOT IN (500,2800,5000);

SELECT product_name,purchase_price
FROM product
WHERE purchase_price NOT IN (500,2800,5000,NULL);

#3.7
SELECT SUM(CASE WHEN sale_price<=1000 THEN product_id ELSE 0 END) AS low_price,
SUM(CASE WHEN sale_price BETWEEN 1001 AND 3000 THEN product_idELSE 0 END) AS mid_price,
SUM(CASE WHEN sale_price>=3001 THEN product_id ELSE 0 END) AS high_price
FROM product;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值