Oracle 日期时间的转换获取[通俗易懂]

Oracle 日期时间的转换获取[通俗易懂]select t.column_name from user_col_comments t where t.table_name = 'BIZ_DICT_XB'; select …

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分

Oracle 日期时间的转换获取[通俗易懂]

 

代码100分
三、最近一个月的“门诊收入”
select  sysdate-30 as 起始日期,sysdate as 截止日期,收入分类 as 统计项目,count(金额) from v_pt_收入分析 where  类别="门诊" and 日期 between  sysdate-30 and sysdate group by 收入分类

Oracle 日期时间的转换获取[通俗易懂]

五、最近一个月的“住院收入”
select  sysdate-30 as 起始日期,sysdate as 截止日期,收入分类 as 统计项目,count(金额) from v_pt_收入分析 where 类别="住院" and 日期 between  sysdate-30 and sysdate  group by 收入分类

Oracle 日期时间的转换获取[通俗易懂]

 

代码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") 

Oracle 日期时间的转换获取[通俗易懂]

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/8467.html

(0)
上一篇 2023-02-27
下一篇 2023-02-27

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注