본문 바로가기
카테고리 없음

pgsql 쿼리 샘플

by Knowledge Store In Hyunsoft 2020. 9. 19.

windows 함수

lead ,leg 함수  

 

select a.* from

(
select reg_dt,
stock_cd,
 cast(extract(epoch from  (reg_dt - (lag(reg_dt) OVER ( ORDER BY stock_cd,reg_dt)))) as integer) AS diff,
 lag(reg_dt) OVER (ORDER BY stock_cd,reg_dt desc) as diff_dt,
 fid_228

from kw_real_data krd 
where 1=1
-- and stock_cd='007570'
and DATE_TRUNC('day', reg_dt) = to_timestamp('20200918', 'YYYYMMDD')
and reg_dt between  to_timestamp('202009180900', 'YYYYMMDDHH24MI') and to_timestamp('202009181520', 'YYYYMMDDHH24MI')
) a
where diff> 200
and fid_228> 100
order by stock_cd,reg_dt
728x90

댓글