d202551
目录
一、175. 组合两个表 - 力扣(LeetCode)
二、511. 游戏玩法分析 I - 力扣(LeetCode)
三、1204. 最后一个能进入巴士的人 - 力扣(LeetCode)
一、175. 组合两个表 - 力扣(LeetCode)
保留一个表的全部数据 使用左连接或右连接
左连接
select p.FirstName,p.LastName,a.city,a.state
from person p left join address a
on p.personId = a.personId
右连接
select p.FirstName,p.LastName,a.city,a.state
from address a right join person p
on p.personId = a.personId
二、511. 游戏玩法分析 I - 力扣(LeetCode)
查询每位玩家 第一次登录平台的日期。
select player_id,min(event_date) as 'first_login'
from Activity
group by player_id
三、1204. 最后一个能进入巴士的人 - 力扣(LeetCode)
使用窗口函数 对于体重进行累加 从当前行累加到第一行
然后对应这个临时表筛选totalWeight <= 1000
然后turn 降序排列
取最后一个
select person_name
from (select person_name,turn,sum(weight) over (order by turn rows between unbounded preceding and current row ) as 'totalWeight'
from Queue) temp
where temp.totalWeight <= 1000
order by turn desc
limit 1