Oracle日期时间的转换获取

database

 

二、最近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")

 

三、最近一个月的“门诊收入”

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 收入分类


 

四、最近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")

以上是 Oracle日期时间的转换获取 的全部内容, 来源链接: utcz.com/z/533624.html

回到顶部