滴滴出行二面笔试题

2020-10-26 14:34:57 浏览数 (1)

在喝奶茶的时候突然收到一封邮件,猝不及防的开始了滴滴出行国际部二面笔试。感觉题目还是比较基础的,我以为会有什么留存率一些比较困难的业务题,慌的我喝了几杯水,没想到十分钟就做完了,中途还接了个推销电话..


学生表:tb_student(name:学生姓名,id:学号,class:班级,in_time:入学时间,age:年龄,sex:性别,major:专业)

1)学生成绩表:tb_score(id:学号,course:课程,score:分数)

1. 筛选出2017年入学的“计算机”专业年龄最小的10位同学名单(姓名、学号、班级、年龄)

代码语言:javascript复制
select a.name,a.id,a.class,a.age
from tb_student a
where year(in_time)=2017 and major="计算机"
order by a.age asc
limit 10

2.统计每个班同学各科成绩平均分大于80分的人数和人数占比

代码语言:javascript复制
SELECT a.class,count(if(b.score>80,true,null)) as numover80,count(if(b.score>80,true,null))/count(score) as total
FROM tb_student a
inner join tb_score b
on a.id=b.id
GROUP BY class
having avg(b.score)>80

2)用户教育经历表:tb_user_edu(uid:用户id,star_date:入学时间,end_date:毕业时间,degree:学历,school:学校,major:专业)

代码语言:javascript复制
select uid
from tb_user_edu
group by uid,end_date
order by end_date
limit 1

3)table1(id:自增id,money:费用)问题:按id顺序累加money,取出累计值与1000相差最小差值的id。

代码语言:javascript复制
select d.id,min(d.差值)
from
(
select c.id,ABS(1000-c.cum) 差值
from
(
SELECT a.id,a.money,SUM(lt.money) as cum
FROM table1 a JOIN table1 lt 
ON a.id >= lt.id
GROUP BY a.id
ORDER BY a.id
)c
)d
group by d.id

这道题犹豫了一下,用多表连接进行累加,然后对做差值进行绝对值化,然后找出绝对值的最小值就是和1000相差最近的了。

4) Employee 表包含所有员工信息,每个员工有其对应的 Id, salary 和 DepartmentId。

---- ------- -------- --------------

| Id | Name | Salary | DepartmentId |

---- ------- -------- --------------

| 1 | Joe | 70000 | 1 |

| 2 | Henry | 80000 | 2 |

| 3 | Sam | 60000 | 2 |

| 4 | Max | 90000 | 1 |

Department 表包含公司所有部门的信息。

---- ----------

| Id | Name |

---- ----------

| 1 | IT |

| 2 | Sales |

---- ----------

编写一个 SQL 查询,找出每个部门工资第二高的员工。

代码语言:javascript复制
select a.name as Department,b.name as Employee,b.salary as Salary
from department a
inner join
(
select *,rank() over(partition by deparmentid order by salary desc) as ranking from employee
)b
on a.id=b.departmentid
where ranking=2

因为没有真实表验证,所以有错误请大家指出,感谢!

0 人点赞