1.编写解决方案,查找那些应该被禁止的Leetflex帐户编号 account_id 。 如果某个帐户在某一时刻从两个不同的网络地址登录了,则这个帐户应该被禁止。
可以以 任何顺序 返回结果。
查询结果格式如下例所示。
select distinct a.account_id
from LogInfo a,
LogInfo b
where a.account_id = b.account_id
and a.ip_address != b.ip_address
and (a.login between b.login and b.logout);
ps:这个也可以自联结inner join做,只要a的登入时间在b在线时间区间就可以了
2.编写解决方案以求得每个员工所在团队的总人数。
返回结果表 无顺序要求 。
返回结果格式示例如下:
select employee_id,count(team_id)over(partition by team_id)as team_size from Employee
3.请编写解决方案,描述每一个玩家首次登陆的设备名称
返回结果格式如以下示例:
select distinct player_id,
first_value(device_id) over (partition by player_id order by event_date) as device_id
from Activity
ps:提问为什么不用select player_id,device_id from Activity group by player_id having min(event_date)? having 后面需要接筛选条件,你这就一个最小数据,所以不可以
4.查找出每个部门中薪资最高的员工。
按 任意顺序 返回结果表。
查询结果格式如下例所示。
select Department, Employee, Salary
from (select e.name Employee,
d.name Department,
e.salary Salary,
rank() over (partition by departmentId order by salary desc) as rank_
FROM Employee e
left join Department d on d.id = e.departmentId) as a
where rank_ = 1