我有一个类似下面的查询
select ref_leger_code,rate,sum(balance),to_char(due_date,'yyyymm')
from tbl_value_temp
group by ref_leger_code,rate,to_char(due_date,'yyyymm');
答案 0 :(得分:2)
我怀疑您正在考虑根据rate
对行进行编号,因此请使用如下分析函数:
select ref_leger_code, rate, sumbalance, due_date,
ROW_NUMBER() OVER (PARTITION BY rate ORDER BY due_date asc ) AS sequence
from (
select ref_leger_code, rate, sum(balance) sumbalance, to_char(due_date,'yyyymm') due_date
from tbl_value_temp
group by ref_leger_code, rate, to_char(due_date,'yyyymm')
);