答案 0 :(得分:2)
您可以在子查询中使用Oracle Analytic Functions。无需加入。
select
r.id,
r.color,
r.shape
from
(
select
s.id,
first_value(s.color) over (partition by s.id order by s.status) as color,
first_value(s.shape) over (partition by s.id order by s.status desc) as shape,
row_number() over (partition by s.id order by s.status) as row_index
from shapes s
) r
where r.row_index = 1;
答案 1 :(得分:-1)
好的,我终于可以写下来了:
Select x.id, x.shape,y.color
from
(Select id ,shape
from Shapes
where status in ( Select max (status)
from shapes
group by id)
) x
join
(Select id , color
from shapes
where status in (Select min(status)
from shapes
group by id )
) y
on x.id = y.id;
欢迎更短的答案