题解 | 医院门诊复诊率与抗生素用药占比统计

医院门诊复诊率与抗生素用药占比统计

https://www.nowcoder.com/practice/7adcef0b1fb741fbba255870422cdb43

with
t1 as(
    select
        dept,
        coalesce(count(visit_id),0) as feb_2024_visits,
        coalesce(count(distinct patient_id),0) as feb_2024_unique_patients
    from visits where left(visit_date,7)='2024-02'
    group by dept),
t2 as(
    select
        b.dept,
        b.visit_id
    from visits a join visits b
    on a.dept=b.dept and a.patient_id=b.patient_id and datediff(b.visit_date,a.visit_date)<=30 and b.visit_date<>a.visit_date-----鸡贼的核心条件,不限定好两天不相等,系统就会把同一天的记录也算一次
    where left(b.visit_date,7)='2024-02'),
t3 as(
    select
        v.dept,
        coalesce(round(sum(if(t2.visit_id=v.visit_id,1,0))*100/count(v.visit_id),2),0) as feb_2024_revisit_rate
    from visits v 
    left join t1 on v.dept=t1.dept
    left join t2 on v.dept=t2.dept
    where left(v.visit_date,7)='2024-02'
    group by v.dept),
t4 as(
    select
        v.dept,
        coalesce(round(sum(p.is_antibiotic)*100/count(p.prescription_id),2),0) as feb_2024_antibiotic_rate
    from visits v left join prescriptions p on v.visit_id=p.visit_id
    where left(v.visit_date,7)='2024-02'
    group by v.dept)

select 
    t1.dept,
    t1.feb_2024_visits,
    t1.feb_2024_unique_patients,
    t3.feb_2024_revisit_rate,
    t4.feb_2024_antibiotic_rate
from t1 
left join t3 on t1.dept=t3.dept 
left join t4 on t1.dept=t4.dept
order by t1.dept

全部评论

相关推荐

2025-12-28 16:32
重庆邮电大学 Java
程序员花海:1.技能放最后,来面试默认你都会,技能没啥用 2.实习写的看起来没啥含金量,多读读部门文档,包装下 接LLM这个没含金量 也不要用重构这种 不会给实习生做的 3.抽奖这个还是Demo项目,实际在公司里面要考虑策略,满减,触发点,触发规则 库存 之类的,不是这个项目这么简单 4.教育背景提前,格式为 教育背景 实习 项目 技能 自我评价
简历被挂麻了,求建议
点赞 评论 收藏
分享
钱嘛数字而已:辅导员肯定不能同意,不然你出事了,他要承担责任。但是,脚和脑子都长在你自己身上,使用它还需要向辅导员报告么? 辅导员必须按流程拒绝你,然后你拿出成年人的态度,做自己的选择。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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