目录
R10-1 商品表查询语句中运算符的使用
本题目要求编写SQL语句,
在sh_goods表中,查询5星好评的商品库存增加850后的值,以及这些商品进行75折促销后的价格。查询结果显示字段依据输出样例设置。
提示:请使用SELECT语句作答。
select name, price old_price, stock old_stock, price*0.75 new_price, stock+850 new_stock
from sh_goods
where score = 5
R10-2 为商品表所有字段添加数据
insert into sh_goods
values
(2,3,'钢笔','001','练字必不可少',15.00,300,3.90,500);
R10-3 为商品表部分字段添加数据
insert into sh_goods
(id,category_id,name,keyword,content)
values
(1,3,'2B铅笔','001','考试专用');
R10-4 删除马齐的购物记录。
delete from recorder
where cid=(select cid from customer where cname='马齐');
R10-5 修改商品库存数量。
update good
set stock = stock-10
where gname like '%爱国者%';
R10-6 获取每个分类下商品的最高价格
select category_id,max(price) max_price
from sh_goods group by category_id;
R10-7 查询商品表中指定价格范围的商品信息
select id,name,price
from sh_goods
where price between 2000 and 6000;
R10-8 查询商品表中指定条件的商品信息(多条件查询)
select id,name,price
from sh_goods
where category_id = 3 and score = 5
R10-9 查询用户评分为5星的商品的评论信息(多表查询)
select sg.name,sgc.content
from sh_goods sg, sh_goods_comment sgc
where sg.id = sgc.goods_id and score = 5
R10-10 创建视图,包含商品打折前后的价格信息
create view view_goods as
select id,name,price old_price,price*0.5 new_price
from sh_goods