SQL编程题复习(24/9/17)

练习题 x40

10-34 查询显示01班所有学生的信息

select *
from student
where GId='01'

10-35 查询显示03班所有女生的信息

select *
from student
where GId='03'
and SSexy='女'

10-36 查询显示刘山同学的电话号码

select STele
from student
where SName like '刘山'

10-37 查询显示所有女生的学号、姓名与班级编号

select SId,SName,GId
from student
where SSexy = '女'

10-38 查询显示年龄在19岁以下的学生的全部信息

select *
from student
where 2023 - year(SBdate) < 19

-- 若没有给定年份则猜 或者 使用 year(curdate())

10-39 查询统计19岁以下学生的总人数(Num)

select count(*) Num
from student
where 2023 - year(SBdate) < 19

-- 若题目没告诉今年为几几年,则 猜

10-40 查询显示CS系的班级名称及入学年份

select GName,GYear
from grade
where DId='CS'

10-41 查询显示没有班主任的班级的所有信息

select *
from grade
-- where TId <=> null  -- ok
where TId is null

10-42 查询显示2008年入学班级的所有信息

select *
from grade
where GYear=2008

10-43 将李飞同学的联系方式改为661010

update student 
set Stele = '661010'
where SName = '李飞'

10-44 如果平时成绩大于90,则将总评成绩低于70的重置为70

update sc
set SCScore = 70
where SCScore1 > 90
and SCScore < 70

-- 重置
-- 使用 update

10-45 将课程"数据库"(课程编号:1)的上课教室改为NB111,授课教师改为李飞(教师编号:02001)

update information
set IRoom='NB111',TId='02001'
where CId = '1'

10-46 将学号为012005001的学生班级改为计算机科学与技术2班(GId=02),联系电话置为空值(NULL)

update student
set GId = '02',STele=null
where SId = '012005001'

10-47 删除所有期末成绩小于60分的选课记录

delete 
from sc
where SCScore3 < 60

10-48 删除学号为012005001的所有选课记录

delete 
from sc
where SId = '012005001'

10-49 删除Product数据表指定商品记录

delete
from Product
where sale_price >= 100

10-50 查询Product表中商品名称包含T恤两字的商品信息,并按登记日期降序排列

select *
from Product
where product_name like '%T恤%'
order by regist_date desc

-- 审题

10-51 查询Product表中进货价格在50至150之间的商品记录。

注意:查询结果中应包含50和150元的商品记录

select *
from Product
where purchase_price between 50 and 150

10-52 查询Product表中进货价格不是15的商品记录

select *
from Product
where purchase_price <> 15

10-53 查询Product表中登记日期在2019年的商品信息,并按销售价格降序排列

select *
from Product
where year(regist_date) = 2019
order by sale_price desc

-- 登记日期为2019年
-- 按销售价格降序排列

10-54 删除Product表中登记日期为NULL的商品记录

delete 
from Product 
-- where regist_date <=> null -- err
where regist_date is null

10-55 将Product表中衣服品类对应的商品销售价格更新为原来的10倍

update Product
set sale_price = sale_price * 10
where product_type = '衣服'

-- 审题

10-56 向Product数据表插入数据

insert into Product
values('0003','高压锅','厨房用具',269,150,'2019-01-15')

10-57 向Product数据表插入数据

insert into Product
values('0003','菜刀','厨房用具',50,20,'2019-09-20')

10-58 查询my_student表中李芳芳同学的学号

select StudentID,StudentName
from my_student
where StudentName = '李芳芳'

10-59 向my_student数据表插入数据

insert into my_student
values('212254203161','李芳芳','女','1999-10-01')

10-60 修改数据表中数据,将李芳芳的生日修改为1999年11月11日

update my_student
set Birth = '1999-11-11'
where StudentName = '李芳芳'

10-61 删除my_student表中学号为212254203161的学生信息

delete
from my_student
where StudentID = '212254203161'

10-62 检索出orders表中所有订单的订单编号,价格和数量

select OrdNo,Price,QTY
from orders

10-63 将sh_goods表中id为8的商品库存由0修改为100

update sh_goods
set stock = 100
where id = 8

10-64 删除sh_goods表中关键词编号为003的商品数据

delete 
from sh_goods
where keyword ='003'

10-65 查询Grade表中课程“Dp010001”的最高分

select max(Grade) max_grade
from Grade
where CourseID = 'Dp010001'

10-66 查询Class表中学生人数大于5人的班级编号

-- select ClassID
-- from Class
-- group by ClassID
-- having sum(StudentNum)>5

select ClassID
from Class
where StudentNum>5

10-67 查询Grade表中课程“Dp010004”的学生学号和成绩,并按成绩降序排列,成绩相同按学号升序排列

select StudentID,Grade
from Grade
where CourseID = 'Dp010004'
order by Grade desc,StudentID asc

10-68 在Teacher表中查询出所有教师所在部门编号,并消除重复记录

select distinct DepartmentID
from Teacher

10-69 查询Student表中出出生日期最大(即年龄最小)的学生姓名及出生日期

-- select StudentName,Birth
-- from Student
-- order by Birth asc
-- limit 1

select top 1
    StudentName,
    Birth
from Student
order by Birth desc

10-70 查询Teacher表中所有教师信息,按教师编号升序排列

select *
from Teacher
order by TeacherID asc

10-71 查询sh_goods表中商品分类编号(category_id)为3,并且用户评分为5星的商品信息

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

10-72 查询sh_goods表中用户评分为4.5或者价格小于10元的商品信息

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

10-73 以sh_goods_category表为主表,sh_goods表为从表,查询商品分类id为10或11的商品对应的商品id、商品名称、分类id及分类名称(——建议二刷

注意:查询结果显示字段依据输出样例设置

-- 查询商品分类id为10或11的商品
-- 对应的商品id、商品名称、分类id及分类名称

-- err
-- select sh_goods.id,sh_goods.name,category_id.id,sh_goods_category.cname
-- from sh_goods
-- join sh_goods_category
-- on sh_goods.id = sh_goods_category.id
-- where category_id in(10,11)


-- 以sh_goods_category表为主表,sh_goods表为从表
select g.id gid,g.name gname,c.id cid,c.name cname
from sh_goods g
right join sh_goods_category c
on g.category_id = c.id -- 商品分类id - 多表连接条件
where c.id in (10,11)

-- 建议二刷
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值