-
20200325 数据库连接查询面试题作业
2020-07-24 10:57#6 查询出语文最高分 SELECT c.Cno,c.Cname,MAX(sc.score) FROM sc INNER JOIN course c ON c.Cno = sc.Cno WHERE c.Cname = '语文'; #8 查询语数外三门成绩的平均分 SELECT c.Cname,AVG(sc.score) FROM sc INNER JOIN course c ON c.Cno = sc.Cno GROUP BY c.Cname; #9 查询报名孤独求败老师课程的学生信息 SELECT s.* FROM teacher t INNER JOIN course c ON c.Tno = t.Tno AND t.Tname = '孤独求败' INNER JOIN sc ON sc.Cno = c.Cno INNER JOIN student s ON s.Sno = sc.Sno -
20200325 数据库连接查询面试题作业
2020-07-24 10:57#6 查询出语文最高分
SELECT MAX(sc.score),course.Cname from lemon_sc as sc INNER JOIN lemon_course as course on course.Cno=sc.Cno and course.Cname like '%语文'#8 查询语数外三门成绩的平均分
SELECT AVG(sc.score),course.Cname from lemon_sc as sc INNER JOIN lemon_course as course on course.Cno=sc.Cno GROUP BY course.Cno#9 查询报名孤独求败老师课程的学生信息
SELECT stu.* from lemon_student as stu INNER JOIN lemon_sc as sc on stu.Sno=sc.Sno INNER JOIN lemon_course as cou on sc.Cno=cou.Cno INNER JOIN lemon_teacher as tea on tea.Tno=cou.Tno where tea.Tname ='孤独求败' -
20200325 数据库连接查询面试题作业
2020-07-24 10:571、 查询出语文最高分 select max(score) as '语文最高分' from sc inner join course as c on c.Cno=sc.Cno where c.Cname='语文' 2、 查询语数外三门成绩的平均分 select c.Cname,avg(sc.score)as '平均分' from course as c inner join sc on c.Cno=sc.Cno group by c.Cno,c.Cname 3、 查询报名孤独求败老师课程的学生信息 select * from student as s inner join sc on s.Sno=sc.Sno inner join course as c on sc.Cno=c.Cno right join teacher as t on t.Tno=c.Tno where t.Tname='孤独求败' -
20200325 数据库连接查询面试题作业
2020-07-24 10:571、 查询出语文最高分
select max(score) as '语文最高分' from sc inner join course as c on c.Cno=sc.Cno
where c.Cname='语文'
2、查询语数外三门成绩的平均分
select c.Cname,avg(sc.score)as '平均分' from course as c inner join sc on c.Cno=sc.Cno
group by c.Cno,c.Cname
3、查询报名孤独求败老师课程的学生信息
select * from student as s inner join sc on s.Sno=sc.Sno
inner join course as c on sc.Cno=c.Cno
right join teacher as t on t.Tno=c.Tno
where t.Tname='孤独求败' -
使用存储过程构造测试数据
2020-07-24 10:57没用,太奇怪了,就那行加了分号就当行报错,不加就下一行报错?不着急吧,老师慢慢看
CREATE DEFINER=
root@localhostPROCEDURECrateTestData()
BEGIN
declare i int default 1;
while i < 10000 do
insert into member values
(null,CONCAT('test_',i),MD5(123456),13517793136+i,1,RAND()*10000,NOW());
set i = i +1;
end while;
END
CALL crateTestData();
-
20200325 数据库连接查询面试题作业
2020-07-24 10:576 查询出语文最高分
select * from course a
inner join sc b on a.Cno=b.Cno
where a.Cname="语文"
order by b.score limit 0, 1 desc;8 查询语数外三门成绩的平均分
select b.Cname, avg(a.score), count(*) from sc a
inner join course b on a.Cno=b.Cno
inner join student c on c.Sno=a.Sno
group by b.Cname, a.score;9 查询报名独孤求败老师课程的学生信息
select * from teacher a
inner join course b on a.Tno=b.Tno and a.Tname="独孤求败"
inner join sc d on d.Sno=b.Sno
right join student c on c.Sno=d.Sno
where b.Cno is not null; -
20200325 数据库连接查询面试题作业
2020-07-24 10:571:
select MAX(score) from sc s inner join course c on s.Cno = c.Cno and c.Cname = '语文'2:
select AVG(s.score),c.Cname from sc s inner join course c on s.Cno = c.Cno
GROUP BY c.Cname;3:
SELECT * from student s inner join sc c on s.Sno = c.Sno
inner join course r on r.Cno = c.Cno
inner join teacher t on t.Tno = r.Tno where t.Tname = '孤独求败' -
20200324 连接查询作业
2020-07-24 10:571、查询张姓员工的员工信息和所在部门信息。
SELECT * FROM emp a LEFT JOIN dept b ON a.dept_id = b.id WHERE a.
nameLIKE '张%'2、查询张三丰管理了几个员工
SELECT count(b.id) FROM emp a INNER JOIN emp b ON a.id = b.leader WHERE a.
name= '张三丰'3、查询出所有实习员工(实习员工无部门信息)
SELECT * FROM emp a LEFT JOIN dept b ON a.dept_id = b.id where b.id IS NULL
-
20200324 连接查询作业
2020-07-24 10:571:select * from emp inner join dept on emp.id=dept.id where emp.name like '张%'
2:
select count() from emp as a inner join emp as b on a.leader = b.id where b.name ='张三丰'
select count() from emp as a inner join emp as b on a.leader = b.id and b.name ='张三丰'
发现第二题用where 和and 的结果是一样的3:select * from emp where dept_id = 0
-
20200324 连接查询作业
2020-07-24 10:57第一题:select * from emp as a inner join dept as
b on a.dept_id=b.id where a.name like '张%';

第二题:select * from emp as a where dept_id=1 and leader=1;

不知道怎么计数
第三题:select * from emp as a where dept_id=1 and leader=1

-
20200324 连接查询作业
2020-07-24 10:57根据课上的emp和dept表完成下列作业:
1、查询张姓员工的员工信息和所在部门信息。
select * from emp as a inner join dept as b on a.dept_id=b.id
where a.name like "张%";
2、查询张三丰管理了几个员工
select count(*) from emp as a inner join emp as b on a.id=b.leader where a.name="张三丰" and b.is_enable=1;
3、查询出所有实习员工(实习员工无部门信息)
select * from emp as a left join dept as b on a.dept_id=b.id
where b.id is null and is_enable=1;






































