select sno,score
from course
join sc on course.cno=sc.cno
where cname like'%数据库%'and score between80and90
10-257 检索出students表中与“陆毅”同一个系的同学姓名。
select sname
from students
where sdept in(select sdept
from students
where sname ='陆毅')and sname <>'陆毅'
10-258 检索出students表和sc表中选修了课号为“0000034”的学生学号和姓名。
select students.sno,sname
from students,sc
where students.sno=sc.sno
and sc.cno ='0000034'
10-259 将身份证号码为152221199710182012的学生所在院部改为“数计学院”。
update student
set dept ='数计学院'where pnum ='152221199710182012'
10-260 将爱国者的库存数量减少10个。(模糊查询)
update good
set stock = stock -10where gname like'爱国者%'-- 模糊查询-- 1.匹配以特定字符开头的字符串:'A%'-- 2.匹配以特定字符结尾的字符串:'%height'-- 3.匹配包含特定字符的字符串:'main'-- 4.匹配特定长度的字符串:-- 例,查找 users 表中所有用户名为三字符的记录(假设用户名只能有三个字符)-- SELECT * -- FROM users-- WHERE username LIKE '___'; -- 三个下划线表示三个字符-- 5.忽略大小写匹配:-- MySQL 的 LIKE 默认是大小写不敏感;-- 如果需要区分大小写,可以使用 BINARY 关键字:-- SELECT * -- FROM employees-- WHERE BINARY name LIKE 'j%';
10-261 删除马齐的购物记录。
deletefrom recorder
where cid in(select cid
from customer
where cname ='马齐')-- 删除-- delete-- from 表名-- where 条件
update recorder
set quantity =1where gid ='G006'and cid in(select cid
from customer
where cname ='杰克')-- update 表名-- set 要修改的列名 = 值-- where-- update 语句中可以使用子查询
查询马齐的购物情况,查询结果以商品编号升序排列。
select good.gid 商品编号,gname 商品名称,price 单价,quantity 购买数量,sale_date 购买日期
from recorder
join good on good.gid=recorder.gid
join customer on customer.cid=recorder.cid
where cname ='马齐'orderby id asc-- 避免 ambiguous 错误
10-265 没有被购买过的商品信息
select*from good
where gid notin(select gid
from recorder
)
10-266 将学号为10001的学生电话号码改为13807589912。
update student
set phone =13807589912where sno ='10001'-- update 表名-- set 要更新列名 = 值-- where 条件-- update 中可以使用子查询
10-267 检索所有选修了40008课的学生学号和成绩,查询结果按学号升序排列。
select sno 学号,grade 成绩
from score
where cno ='40008'
10-268 查询数计学院学生总人数
selectcount(sno) 总人数
from student
where dept ='数计学院'
10-269 统计每个学院的学生总人数
select dept 院部,count(sno) 总人数
from student
groupby dept
-- 每个学院,通过学院分组