一、单表查询现有数据库casemanage中表结构如下图TABLENAME:afinfo1)请编写sql语句对年龄进行升序排列select * from afinfo order by birth;2)请编写sql语句查询对“徐”姓开头的人员名单select * from afinfo where name like '徐%';3)请编写sql语句修改“陈晓”的年龄为“45”update afinfo set age=45 and birth=birth-YEAR(45) where; 错误原因拆解: SET 子句使用了错误的 AND UPDATE 语句中,多个字段赋值应该用 ** 逗号 ,** 分隔,而不是 AND。 AND 是 WHERE 子句的逻辑运算符,写在 SET 里会被解析为逻辑判断,导致语法异常。 birth=birth-YEAR(45) 是无效语法 YEAR() 函数需要传入一个日期 / 时间字段,而不是数字 45;birth-YEAR(...) 这种运算方式也完全错误,无法实现日期的加减。 数据类型错误 由于上述语法错误,MySQL 会错误地尝试将 45 作为日期时间值解析,因此报出了 Incorrect datetime value: '45' 错误。正确写法:UPDATE ainfo SET age = 45, birth = DATE_SUB(CURDATE(), INTERVAL 45 YEAR) WHERE name = '陈晓';UPDATE ... SET 多字段赋值4)请编写sql删除王芳芳这表数据记录。delete from afinfo where;二、双表查询现有以下几个表:学生信息表(student)考试信息表(exam)1)查询出所有学生信息,SQL怎么编写?select * from stu;2)新学生小明,学号为005,需要将信息写入学生信息表,SQL语句怎么编写?insert into stu values ("小明",005);3)李四语文成绩被登记错误,成绩实际为85分,更新到考试信息表中,SQL语句怎么编写update examsetscore=85where id=(select id from stu where) and subject="语文";4)查询出各科成绩的平均成绩,显示字段为:学科、平均分,SQL怎么编写?select subject,avg(score) from exam group by subject;5)查询出所有学生各科成绩,显示字段为:姓名、学号、学科、成绩,并以学号与学科排序,没有成绩的学生也需要列出,SQL怎么编写?select s.name,s.code,e.subject,e.score from student sleft join exam e on s.code=e.codeorder by code,subject;6)查询出单科成绩最高的,显示字段为:姓名、学号、学科、成绩,SQL怎么编写?select s.name,s.code,e.subject,e.score from student sjoin exam e on s.code=e.codewhere (e.subject,e.score) in (select subject,max(score) from exam group by subject);各科最高分: M=select subject,max(score) from exam group by subject写法2:(错误)select s.name,s.code,e.subject,MAX(e.score) from student sjoin exam e on s.code=e.codegroup by subject报错如下:group by subject 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column '双表查询.s.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 时间: 0s7)列出每位学生的各科成绩,要求输出格式:姓名、学号、语文成绩、数学成绩、英语成绩,SQL怎么编写?select name,code,max(case when subject="语文" then score else 0 end)as 语文,max(case when subject="数学" then score else 0 end)as 数学,max(case when subject="英语" then score else 0 end)as 英语from (select s.name,s.code,e.subject,e.scorefrom student s left join exam e on s.code=e.code order by e.subject)as a group by a.code;三、四表联查根据要求写出SQL语句:Student(s_no,sname,sage,sex)学生表Sc(s_no,c_no,score)成绩表Course(c_no,cname,t_no)课程表Teacher(t_no,tname)教师表1、查询“001”课程比“002”课程成绩高的所有学生的学号。select a.s_no from(select s_no,score from Sc where c_no='1') a,(select s_no,score from Sc where c_no='2') bwhere a.scoreb.score and a.s_no=b.s_no;2、查询平均成绩大于60分的同学的学号和平均成绩。select s_no,avg(score) from Scgroup by s_nohaving avg(score)60;3、查询所有同学的学号、姓名、选课数、总成绩。select Student.s_no,Student.sname,count(Sc.c_no),sum(score) from Studentleft outer join Sc on Student.s_no=Sc.s_nogroup by Student.s_no, Student.sname;4、查询姓李的老师的个数。select count(distinct(tname)) from Teacher where tname like '李%';5、查询没学过“叶平”老师课的同学的学号、姓名select Student.s_no,Student.sname from Studentwhere s_no not in(select