恒生电子SQL题第三题
with t1 as (select
finance_mic,prod_code,trade_date,data_timestamp,
round(data_timestamp / 100000) flag,
count(*) over (partition by round(data_timestamp / 100000) order by data_timestamp) cnt,
first_value(last_px) over (partition by round(data_timestamp / 100000 ) order by data_timestamp) open_px,
last_value(last_px) over (partition by round(data_timestamp / 100000 ) order by data_timestamp) close_px,
max(last_px) over (partition by round(data_timestamp / 100000 ) order by data_timestamp) high_px,
min(last_px) over (partition by round(data_timestamp / 100000 ) order by data_timestamp) low_px
from hq_stock_snapshot
where finance_mic = 'XSHG' and prod_code = '600570'
and trade_date = 20230703 and data_timestamp >= 93000000 and data_timestamp < 100000000
)
select
finance_mic, prod_code, trade_date, data_timestamp,open_px,high_px,low_px,close_px
from
(
select *,row_number() over (partition by flag order by cnt desc) rk from t1
)t2 where rk = 1;
finance_mic,prod_code,trade_date,data_timestamp,
round(data_timestamp / 100000) flag,
count(*) over (partition by round(data_timestamp / 100000) order by data_timestamp) cnt,
first_value(last_px) over (partition by round(data_timestamp / 100000 ) order by data_timestamp) open_px,
last_value(last_px) over (partition by round(data_timestamp / 100000 ) order by data_timestamp) close_px,
max(last_px) over (partition by round(data_timestamp / 100000 ) order by data_timestamp) high_px,
min(last_px) over (partition by round(data_timestamp / 100000 ) order by data_timestamp) low_px
from hq_stock_snapshot
where finance_mic = 'XSHG' and prod_code = '600570'
and trade_date = 20230703 and data_timestamp >= 93000000 and data_timestamp < 100000000
)
select
finance_mic, prod_code, trade_date, data_timestamp,open_px,high_px,low_px,close_px
from
(
select *,row_number() over (partition by flag order by cnt desc) rk from t1
)t2 where rk = 1;
全部评论
牛
我超,这么猛
666.别的呢
读了好久题目才读懂,好恶心
相关推荐
点赞 评论 收藏
分享
06-12 17:46
门头沟学院 Java 
点赞 评论 收藏
分享