한개의 테이블 a컬럼 타입의 합계금액. b컬럼 타입의 합계금액
a와 b 조건값에 합계금액을 비교하는 쿼리는 어떻게 되나요?
도움 부탁 드립니다.
조건 | 합계 | |
1 | a | 1 |
2 | b | 2 |
Comment 2
-
joe
2015.09.16 13:29
-
;with a(c1, c2, c3) as (select 1, 'a', 2 union allselect 2, 'b', 3), b as (select c2, c3, lead(c3, 1, null) over(order by c1) as c3sfrom a)select *from bwhere c3s is not null
with aa as (
select 1 값, 'a' 조건
--union all
--select 3 값, 'a' 조건
union all
select 2 값 , 'b' 조건
--union all
--select 5 값 , 'c' 조건
)
select bb.*
, convert(varchar,dense_rank() over (order by bb.합계 desc))+'번째로 큼'
from
(
select aa.*
, sum(값) over(partition by 조건) 합계
from aa
) bb