大家好,我是考100分的小小码 ,祝大家学习进步,加薪顺利呀。今天说一说Oracle 日期时间的转换获取[通俗易懂],希望您对编程的造诣更进一步.
二、最近3个月的“门诊人次”和前一年的相同月份的“门诊人次”
select extract(year from sysdate) as 年份,(to_char(sysdate,"MM")-1) as 月份,"门诊人次" as 统计项目,count(门诊人次) from v_pt_门诊人次 where to_char(日期,"YYYY/MM") = to_char(sysdate-30,"YYYY/MM")
union all
select extract(year from sysdate) as 年份,(to_char(sysdate,"MM")-2) as 月份,"门诊人次" as 统计项目,count(门诊人次) from v_pt_门诊人次 where to_char(日期,"YYYY/MM") = to_char(sysdate-60,"YYYY/MM")
union all
select extract(year from sysdate) as 年份,(to_char(sysdate,"MM")-3) as 月份,"门诊人次" as 统计项目,count(门诊人次) from v_pt_门诊人次 where to_char(日期,"YYYY/MM") = to_char(sysdate-90,"YYYY/MM")
union all
select extract(year from sysdate)-1as 年份,(to_char(ADD_MONTHS(sysdate, -12),"MM")-1) as 月份,"门诊人次" as 统计项目,count(门诊人次) from v_pt_门诊人次 where to_char(日期,"YYYY/MM") = to_char(ADD_MONTHS(sysdate, -12),"YYYY/MM")
union all
select extract(year from sysdate)-1 as 年份,(to_char(ADD_MONTHS(sysdate, -12),"MM")-2) as 月份,"门诊人次" as 统计项目,count(门诊人次) from v_pt_门诊人次 where to_char(日期,"YYYY/MM") = to_char(ADD_MONTHS(sysdate, -13),"YYYY/MM")
union all
select extract(year from sysdate)-1 as 年份,(to_char(ADD_MONTHS(sysdate, -12),"MM")-3) as 月份,"门诊人次" as 统计项目,count(门诊人次) from v_pt_门诊人次 where to_char(日期,"YYYY/MM") = to_char(ADD_MONTHS(sysdate, -14),"YYYY/MM")
代码100分
代码100分
三、最近一个月的“门诊收入”
select sysdate-30 as 起始日期,sysdate as 截止日期,收入分类 as 统计项目,count(金额) from v_pt_收入分析 where 类别="门诊" and 日期 between sysdate-30 and sysdate group by 收入分类
五、最近一个月的“住院收入”
select sysdate-30 as 起始日期,sysdate as 截止日期,收入分类 as 统计项目,count(金额) from v_pt_收入分析 where 类别="住院" and 日期 between sysdate-30 and sysdate group by 收入分类
代码100分
四、最近3个月的“出院人数”和前一年的相同月份的“出院人数”
select extract(year from sysdate) as 年份,(to_char(sysdate,"MM")-1) as 月份,"出院人数" as 统计项目,count(出院人数) from v_pt_住院人次 where to_char(日期,"YYYY/MM") = to_char(sysdate-30,"YYYY/MM")
union all
select extract(year from sysdate) as 年份,(to_char(sysdate,"MM")-2) as 月份,"出院人数" as 统计项目,count(出院人数) from v_pt_住院人次 where to_char(日期,"YYYY/MM") = to_char(sysdate-60,"YYYY/MM")
union all
select extract(year from sysdate) as 年份,(to_char(sysdate,"MM")-3) as 月份,"出院人数" as 统计项目,count(出院人数) from v_pt_住院人次 where to_char(日期,"YYYY/MM") = to_char(sysdate-90,"YYYY/MM")
union all
select extract(year from sysdate)-1as 年份,(to_char(ADD_MONTHS(sysdate, -12),"MM")-1) as 月份,"出院人数" as 统计项目,count(出院人数) from v_pt_住院人次 where to_char(日期,"YYYY/MM") = to_char(ADD_MONTHS(sysdate, -12),"YYYY/MM")
union all
select extract(year from sysdate)-1 as 年份,(to_char(ADD_MONTHS(sysdate, -12),"MM")-2) as 月份,"出院人数" as 统计项目,count(出院人数) from v_pt_住院人次 where to_char(日期,"YYYY/MM") = to_char(ADD_MONTHS(sysdate, -13),"YYYY/MM")
union all
select extract(year from sysdate)-1 as 年份,(to_char(ADD_MONTHS(sysdate, -12),"MM")-3) as 月份,"出院人数" as 统计项目,count(出院人数) from v_pt_住院人次 where to_char(日期,"YYYY/MM") = to_char(ADD_MONTHS(sysdate, -14),"YYYY/MM")
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/8467.html