l*******y 发帖数: 11 | 1 我的数据情况如下:
每个ID有多组重复测量的值,但是有的没有测量值
ID field1 field2 filed3
1
1 z
1 x y Null
2 a
2 Null b c
.
.
.
n
n e f
n d Null Null
想通过query得到每个field最后一个非空的数值,即:
ID field1 field2 filed3
1 x y z
2 a b c
...
n d e f
用total,last 得出的只能得到最后一组值:
ID field1 field2 filed3
1 x y Null
2 Null b c
n d Null Null
谢谢大家啦! | i****a 发帖数: 36252 | 2 select id, max(field1) as f1, max(field2) as f2
from table
group by id | l*******y 发帖数: 11 | 3 请问是用最大值(max)吗?这样能得到最后一个值吗 | B*****g 发帖数: 34098 | 4 select t1.id, t1.f1,t2.f2,t3.f3
from (select id, last(field1) as f1
from table1
where field1 is not null
group by id) t1,
(select id, last(field2) as f2
from table1
where field2 is not null
group by id) t2,
(select id, last(field3) as f3
from table1
where field3 is not null
group by id) t3
where t1.id = t2.id
and t1.id= t3.id
or
select t0.id,
(select last(t1.field1) from table1 t1 where t1.id = t0.id and t1.fie
ld1 is not null) AS field1,
(select last(t2.field2) from table1 t2 wher
【在 l*******y 的大作中提到】 : 我的数据情况如下: : 每个ID有多组重复测量的值,但是有的没有测量值 : ID field1 field2 filed3 : 1 : 1 z : 1 x y Null : 2 a : 2 Null b c : . : .
| l*******y 发帖数: 11 | 5 Thank you so much Beijing! It works!! |
|