pta mysql训练题集(361-380)

10-361 查询商品表中部分字段

select id,category_id,name from sh_goods;

10-362 简单条件查询数据

select * from sh_goods where id = 1;

10-363 修改商品表价格数据

update sh_goods set price = 30 where id = 2

10-364 删除商品表数据

delete from sh_goods where category_id != 3;

10-365 获取每个分类下商品的最高价格

select category_id,max(price) as max_price
from sh_goods
group by category_id;

10-366 查询商品表中商品库存的最高和最低值

select max(stock) as stock1,min(stock) as stock2
from sh_goods;

10-367 获取指定条件商品的平均价格

select category_id,avg(price) as average
from sh_goods
group by category_id
having count(*) > 2

10-368 商品表查询语句中运算符的使用

select name,price as old_price,stock as old_stock,price*0.75 as new_price,stock+850 as new_stock
from sh_goods
where score = 5

10-369 查询商品表中用户评分在前20%的商品名称

select top 20 percent
name
from sh_goods
order by score desc;
-- percent 百分比

10-370 查询商品表中指定价格范围的商品信息

select id,name,price
from sh_goods
where price between 2000 and 6000;

10-371 商品表中判断字段是否为NULL

select id,name,price
from goods
where price is null;

10-372 获取商品表中商品名称含有“pad”的商品

select id,name,price
from goods
where name like '%pad%';

10-373 查询商品表中指定条件的商品信息(多条件查询)

select id,name,price
from sh_goods
where category_id = 3 and score = 5;

10-374 查询商品表中指定条件的商品信息(多条件查询)

select name,price,score
from sh_goods
where score = 4.5 or price < 10;

10-375 查询没有任何评论信息的商品id和name(多表查询)

select id,name
from sh_goods
where id not in (select goods_id as id from sh_goods_comment);

10-376 查询用户评分为5星的商品的评论信息(多表查询)

select name,b.content
from sh_goods as a, sh_goods_comment as b
where a.id = b.goods_id and score=5;

10-377 统计学校已开设的课程门数。

select count(*) as 开设课程数
from course

10-378 查询数计学院学生总人数。

select count(*) as 数计学院总人数
from student
where dept = '数计学院'

10-379 查询2018-2019(2)学期选修课程号为2201(数据库课程)的学生平均成绩。

select avg(grade) as 数据库课平均成绩
from score
where cno = '2201' and term = '2018-2019(2)';

10-380 统计每个学院的学生总人数,并按人数降序排列。

select dept as 院部,count(*) as 总人数
from student
group by dept
order by count(*) desc;

你可能感兴趣的:(狂刷MYSQL,mysql,数据库)