一个数据分析培训机构的测试题
sql执行顺序
sql
- 查询「李」姓老师的数量
select count(Tname) from Teacher where Tname like '李%'
- 查询" 01 "课程比" 02 "课程成绩高的学生的信息及课程分数
select a.SId, s.Sname, s.Sage, s.Ssex, a.score as 1_score, b.score as 2_score
from sc a
inner join sc b
on a.SId = b.SId and a.CId = '01' and b.CId = '02'
inner join Student s
on a.SId = s.SId
where a.score > b.score
- 查询同时存在" 01 "课程和" 02 "课程的情况
select *
from sc a
inner join sc b
on a.SId = b.SId and a.CId = '01' and b.CId = '02'
- 查询存在" 01 "课程但可能不存在" 02 "课程的情况(不存在时显示为 null )
select *
from sc a
left join sc b
on a.SId = b.SId and b.CId = '02'
where a.CId = '01'
- 查询不存在" 01 "课程但存在" 02 "课程的情况
select *
from sc a
inner join sc b
on a.SId = b.SId and b.CId <> '01'
where a.CId = '02'
- 查询平均成绩大于等于 60 分的同学的学生编号和学生姓名和平均成绩
select s.SId, s.Sname, avg(a.score)
from SC a
inner join Student s
on a.SId = s.SId
group by a.SId
having avg(a.score) > 60
- 查询在 SC 表存在成绩的学生信息
select *
from Student
where SId in (select distinct SID from SC)
- 查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩(没成绩的显示为 null )
select s.SId, s.Sname, count(a.CId), sum(a.score)
from Student s
left join SC a
on s.SId = a.SId
group by s.SId
Python
- 用户从终端输入一个分数,程序输出这个分数所属的考评等级,90到100分是A,60到89是B,60分以下是C
def grade_rank(x):
if not x:
return '请重新输入'
if x<60:
return 'C'
elif x<89:
return 'B'
else:
return 'A'
x = int(input('input score:\n'))
print(grade_rank(x))
- 有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和
from fractions import Fraction
up = 2
down = 1
sum = 0
for i in range(20):
sum += Fraction(up/down)
up, down = up+down, up
print(sum)
- 猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。
x = 1
for i in range(9):
x = 2*(x+1)
print(x)
- 请用面对对象的思想编写一个小游戏,人狗大站,2个角色,人和狗,游戏开始后,生成2个人,3条狗,互相混战,人被狗咬了会掉血,狗被人打了也掉血,狗和人的攻击力,具备的功能都不一样。
有点问题。。。
- 一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?第10次反弹多高?
dis = 100
total = dis
dis /= 2
for x in range(9):
total += dis * 2
dis /= 2
print(dis, total)
网友评论