603. 连续空余座位
编写一个SQL查询来报告电影院所有连续可用的座位。
返回按== seat_id 升序排序 ==的结果表。
测试用例的生成使得两个以上的座位连续可用。
查询结果格式如下所示。
select
distinct a.seat_id
from
Cinema as a cross join Cinema as b on abs(a.seat_id-b.seat_id)=1
and a.free=1 and b.free=1
order by
1
1731. 每位经理的下属员工数量
对于此问题,我们将至少有一个其他员工需要向他汇报的员工,视为一个经理。
编写SQL查询需要听取汇报的所有经理的ID、名称、直接向该经理汇报的员工人数,以及这些员工的平均年龄,其中该平均年龄需要四舍五入到最接近的整数。
返回的结果集需要按照 employee_id 进行排序。
查询结果的格式如下:
select
e1.employee_id,
e1.name,
count(*) as reports_count,
round(avg(e2.age),0) as average_age
from
Employees as e1 join Employees as e2 on e1.employee_id= e2.reports_to
# where
# e1.reports_to is null and e2.reports_to is not null 不能这样写,有的经理可能也是有经理
group by
1
order by
1
1747. 应该被禁止的 Leetflex 账户
编写一个SQL查询语句,查找那些应该被禁止的Leetflex帐户编号 account_id 。 如果某个帐户在某一时刻从两个不同的网络地址登录了,则这个帐户应该被禁止。
可以以 任何顺序 返回结果。
查询结果格式如下例所示。
select
distinct a.account_id
from
LogInfo as a join LogInfo as b on a.account_id=b.account_id
and a.ip_address != b.ip_address # 异地登录
and a.logout between b.login and b.logout
181. 超过经理收入的员工
编写一个SQL查询来查找收入比经理高的员工。
以 任意顺序 返回结果表。
查询结果格式如下所示。
select
e2.name as Employee
from
Employee as e1 join Employee as e2 on e1.id = e2.managerId
and e1.salary < e2.salary