id string,//利率的类型
times date,//更改时间
val string//利率值
//外部表
create external table rate_w(
id string,
times date,
val string
)
row format delimited fields terminated by ','
location '/warehouse/rate';
hadoop fs -put rate /warehouse/rate
1,2018-01-01,11
1,2018-01-01,1
12,2018-01-01,3
52,018-01-01,52
5,2018-01-01,21
3,2018-05-01,32
3,2018-04-01,32
1,2018-03-01,42
2,2018-03-02,11
2,2018-02-01,21
select * from rate_w;
1 2018-01-01 11
1 2018-01-01 1
12 2018-01-01 3
52 NULL 52
5 2018-01-01 21
3 2018-05-01 32
3 2018-04-01 32
1 2018-03-01 42
2 2018-03-02 11
2 2018-02-01 21
select d.* from rate_w d right join
(
select b.id,max(times) as t from (
select a.id,a.times,a.val from rate_w a where times>='2018-01-01'
) b group by b.id
) c
on d.times=c.t and d.id=c.id;
//找出某个时间以内,更改的值的最新来,使用group by join on 子连接
1 2018-03-01 42
12 2018-01-01 3
2 2018-03-02 11
3 2018-05-01 32
5 2018-01-01 21
sql找出更改后的利率值
最新推荐文章于 2022-03-28 23:11:43 发布