상태와 위치가있는 테이블이 있는데 다음은 데이터입니다. 맞춤 주문을 사용하여 위치별로 분할 된 최대 상태를 얻고 싶습니다. 무엇을 변경해야하는지 아십니까? 지금은 내가 언급 한 순서에 관계없이 최대 값만 제공하고 있습니다.
맞춤 주문은 1> 3> 2입니다.
status | location
1 | 11
2 | 11
2 | 12
3 | 12
3 | 11
위치 11에 대한 예상 결과 : 1 위치 12 : 3에 대한 예상 결과
질문:
select max(status) over (partition by location order by decode(status, '1',6,'3',5,'2',4,3)
rows between unbounded preceding and unbounded following) mx from items;
http://sqlfiddle.com/#!4/ed9e7e/13
create table items
( status varchar2(1), location number(9)
);
insert into items values('1',123);
insert into items values('2',123);
insert into items values('3',123);
insert into items values('4',123);
나는 당신이 원한다고 생각합니다 first_value()
:
select first_value(status) over (partition by location
order by decode(status, '1', 6, '3', 5, '2', 4, 3)
) mx
from items;
저는을 좋아하지는 decode()
않지만 원하는 것을 간결하게 표현할 수 있습니다. 나는 case
표현을 선호 합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다