题解 | #分别满足两个活动的人#

分别满足两个活动的人

http://www.nowcoder.com/practice/a126cea91d7045e399b8ecdcadfb326f

看了几个题发现对第二个条件至少有一次用了一半时间就完成高难度试卷且分数大于80的人(activity2)发了福利券的处理都是放在where里筛选,其实当然可行,毕竟这道题之后直接group by uid那么不影响uid出现次数。

我就写一下至少一次的满足条件sql写法吧:

select uid,
       'activity1' as activity
from exam_record
where year(start_time)=2021
group by uid
having count(if(score>=85,1,null))=count(start_time)

union ALL

select uid,
       'activity2' as activity
from exam_record
left join examination_info using(exam_id)
where difficulty='hard' and score>80 and year(start_time)=2021
group by uid
having count(if(timestampdiff(second,start_time,submit_time)/60<=duration/2,1,null))>=1
order by uid asc
全部评论

相关推荐

程序员花海:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务