时间:2021-07-01 10:21:17 帮助过:10人阅读
插入数据
#学生表 insert into student values(‘01‘ , ‘赵雷‘ , ‘1990-01-01‘ , ‘男‘); insert into student values(‘02‘ , ‘钱电‘ , ‘1990-12-21‘ , ‘男‘); insert into student values(‘03‘ , ‘孙风‘ , ‘1990-05-20‘ , ‘男‘); insert into student values(‘04‘ , ‘李云‘ , ‘1990-08-06‘ , ‘男‘); insert into student values(‘05‘ , ‘周梅‘ , ‘1991-12-01‘ , ‘女‘); insert into student values(‘06‘ , ‘吴兰‘ , ‘1992-03-01‘ , ‘女‘); insert into student values(‘07‘ , ‘郑竹‘ , ‘1989-07-01‘ , ‘女‘); insert into student values(‘08‘ , ‘王菊‘ , ‘1990-01-20‘ , ‘女‘); #课程表 insert into course values(‘01‘ , ‘语文‘); insert into course values(‘02‘ , ‘数学‘); insert into course values(‘03‘ , ‘英语‘); #教师表 insert into teacher values(‘01‘ , ‘张三‘,‘01‘); insert into teacher values(‘02‘ , ‘李四‘,‘02‘); insert into teacher values(‘03‘ , ‘王五‘,‘03‘); #成绩表 insert into grade values(1,80,‘01‘ , ‘01‘); insert into grade values(2,90,‘01‘ , ‘02‘); insert into grade values(3,99,‘01‘ , ‘03‘); insert into grade values(4,70,‘02‘ , ‘01‘); insert into grade values(5,60,‘02‘ , ‘02‘); insert into grade values(6,80,‘02‘ , ‘03‘); insert into grade values(7,80,‘03‘ , ‘01‘); insert into grade values(8,80,‘03‘ , ‘02‘); insert into grade values(9,80,‘03‘ , ‘03‘); insert into grade values(10,50,‘04‘ , ‘01‘); insert into grade values(11,30,‘04‘ , ‘02‘); insert into grade values(12,20,‘04‘ , ‘03‘); insert into grade values(13,76,‘05‘ , ‘01‘); insert into grade values(14,87,‘05‘ , ‘02‘); insert into grade values(15,31,‘06‘ , ‘01‘); insert into grade values(16,34,‘06‘ , ‘03‘); insert into grade values(17,89,‘07‘ , ‘02‘); insert into grade values(18,98,‘07‘ , ‘03‘);
练习题和sql语句
#1 查询01课程比02课程成绩高的学生的信息以及课程分数 # 找出课程为01的学生的学生信息以及成绩 # 找出课程为02的学生的学生信息以及成绩 data_1 = session.query(Grade.stu_id,Grade.cou_id,Grade.score).filter(Grade.cou_id==1).subquery() data_2 = session.query(Grade.stu_id,Grade.cou_id,Grade.score).filter(Grade.cou_id==2).subquery() data_3 = session.query(data_1.c.stu_id).filter(data_1.c.stu_id==data_2.c.stu_id,data_1.c.score>data_2.c.score).subquery() #学生信息 data_4 = session.query(Stu).filter(Stu.id == data_3.c.stu_id).all() #课程分数 data_5 = session.query(Stu.name,data_1.c.stu_id,data_1.c.score,data_2.c.score).filter( data_1.c.stu_id==data_2.c.stu_id, data_1.c.score>data_2.c.score, Course.id==data_1.c.cou_id, Stu.id == data_1.c.stu_id, ).all() print([v for v in data_5])
mysql语句练习50题(sqlalchmey写法)
标签:tail mys utf8 练习题 lse har lte orm ima