SQL257 刷题通过的题目排名
select
id,
number,
dense_rank()over(order by number desc) as t_rank
from passing_number
order by `number`desc,id
SQL258 找到每个人的任务
select a.id,a.name,b.content
from person as a
left join task as b
on a.id=b.person_id
order by a.id
SQL259 异常的邮件概率
select
a.date,
round(sum(case when type='completed' then 0 else 1 end)/count(*),3) as p
from email as a
join user as b on a.send_id=b.id
join user as c on a.receive_id=c.id
where send_id !=2 and receive_id !=2
group by `date`
order by `date`
SQL260 牛客每个人最近的登录日期(一)
select
user_id,
max(date) as id
from login
group by user_id
order by user_id
SQL261 牛客每个人最近的登录日期(二)
select
b.name as u_n,
c.name as c_n,
a.date as date
from login as a
left join user as b on a.user_id=b.id
left join client as c on a.client_id=c.id
where (a.user_id,a.date) in
(select user_id,max(date) from login group by user_id)
order by u_n
SQL262 牛客每个人最近的登录日期(三)
select
round(count(distinct user_id)/(select count(distinct user_id) from login),3)
from login
where (user_id,date) in(
select user_id,date_add(min(date),interval 1 day) from login group by user_id
)
SQL263 牛客每个人最近的登录日期(四)
select
date,
count(distinct (case when (user_id,date) in
(select user_id,min(`date`) as date from login group by user_id)
then user_id else null end )) as new
from login
group by date
order by date
SQL264 牛客每个人最近的登录日期(五)
select t0.date,
ifnull(round(count(distinct t2.user_id)/(count(t1.user_id)),3),0)
from
(
select date
from login
group by date
) t0
left join
(
select user_id,min(date) as date
from login
group by user_id
)t1
on t0.date=t1.date
left join login as t2
on t1.user_id=t2.user_id and datediff(t2.date,t1.date)=1
group by t0.date
SQL265 牛客每个人最近的登录日期(六)
select
b.name as u_n,
a.date,
sum(a.number)over(partition by a.user_id order by a.date) as ps_num
from passing_number as a
join user as b on a.user_id=b.id
order by a.date,u_n