取前30分钟断面数据

数据需求:

1)当前分钟数>30,取当前时段0-30分钟断面的数据

2)当前分钟数<30,取上个时段30-60分钟断面的数据


select to_number(to_char(sysdate, 'mi')) as 当前分钟 from dual;
select to_date(to_char(sysdate, 'yyyy-mm-dd hh24') || '0000', 'yyyy-mm-dd hh24:mi:ss') as 当前整点 from dual;
select to_date(to_char(sysdate, 'yyyy-mm-dd hh24') || '3059', 'yyyy-mm-dd hh24:mi:ss') as 当前30分 from dual;
select to_date(to_char(sysdate-1/24, 'yyyy-mm-dd hh24') || '3100', 'yyyy-mm-dd hh24:mi:ss') as 上个30分 from dual;
select to_date(to_char(sysdate-1/24, 'yyyy-mm-dd hh24') || '5959', 'yyyy-mm-dd hh24:mi:ss') as 上个整点 from dual;

-------------查询当前系统时间---------
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss' ) as 系统时间 from dual;

select to_number(to_char(sysdate, 'mi')) from dual;
select to_date(to_char(sysdate, 'yyyy-mm-dd hh24') || '0000', 'yyyy-mm-dd hh24:mi:ss') from dual;
select to_date(to_char(sysdate, 'yyyy-mm-dd hh24') || '3059', 'yyyy-mm-dd hh24:mi:ss') from dual;
select to_date(to_char(sysdate-1/24, 'yyyy-mm-dd hh24') || '3100', 'yyyy-mm-dd hh24:mi:ss') from dual;
select to_date(to_char(sysdate-1/24, 'yyyy-mm-dd hh24') || '5959', 'yyyy-mm-dd hh24:mi:ss') from dual;

-----取前30分钟断面数据---------------
select *
  from Z_FINANCE_SCREEN_REAL_TIME  t
 where t.gathertime
       between to_date(to_char(sysdate, 'yyyy-mm-dd hh24') || '0000', 'yyyy-mm-dd hh24:mi:ss') 
       and to_date(to_char(sysdate, 'yyyy-mm-dd hh24') || '3059', 'yyyy-mm-dd hh24:mi:ss')
       and to_number(to_char(sysdate, 'mi')) >= 30
union all
select *
  from Z_FINANCE_SCREEN_REAL_TIME  t
 where t.gathertime 
       between to_date(to_char(sysdate-1/24, 'yyyy-mm-dd hh24') || '3100', 'yyyy-mm-dd hh24:mi:ss') 
       and to_date(to_char(sysdate-1/24, 'yyyy-mm-dd hh24') || '5959', 'yyyy-mm-dd hh24:mi:ss')
       and to_number(to_char(sysdate, 'mi')) < 30;

你可能感兴趣的:(#,数据库开发,数据库开发,SQL)