create table 銘柄(
銘柄コード char(5),
日付 date,
初値 number(3),
高値 number(3),
安値 number(3),
終値 number(3));
insert into 銘柄 values('11111',to_date('2004-03-04','YYYY/MM/DD'),100,150, 80,120);
insert into 銘柄 values('11111',to_date('2004-03-05','YYYY/MM/DD'),120,200,120,200);
insert into 銘柄 values('11111',to_date('2004-03-08','YYYY/MM/DD'),100,180,100,170);
insert into 銘柄 values('11111',to_date('2004-03-09','YYYY/MM/DD'),180,190,170,180);
insert into 銘柄 values('22222',to_date('2004-03-04','YYYY/MM/DD'),200,250,180,220);
insert into 銘柄 values('22222',to_date('2004-03-05','YYYY/MM/DD'),220,300,220,300);
insert into 銘柄 values('22222',to_date('2004-03-08','YYYY/MM/DD'),200,280,200,270);
insert into 銘柄 values('22222',to_date('2004-03-09','YYYY/MM/DD'),280,290,270,280);
commit;
col 初値 for 9999
col 高値 for 9999
col 安値 for 9999
col 終値 for 9999
select 銘柄コード,日付,初値,高値,安値,終値,
Lag(終値,1,終値)
over(partition by 銘柄コード order by 日付) as 前日終値,
round(高値/
Lag(終値,1,終値) over(partition by 銘柄コード order by 日付)*100,2) as 高値前日終値比,
round(安値/
Lag(終値,1,終値) over(partition by 銘柄コード order by 日付)*100,2) as 安値前日終値比
from 銘柄
order by 銘柄コード,日付;