我有一个如下的桌子:
预期结果如下:
这里的T1是上个月,T2是上个月的最后一个,T3从现在开始3个月,依此类推。
total_inactivity =金额为0
max_consectee_inactivity =连续数月的最大数量为零的月数=零最近
_inactivity =最近从最近一个月开始的连续数月的最大数量,即t1 t1 t1 the the金额为0。这意味着如果T1表示T1除零外,有任何值,最近的inActivity将为零。例如,自t1_amount,t2_amount,t3_amount和t4_amount以来,Person_ID 5555的近期_ Inactivity = 4,全部为0。nb
:我有大约1000万个记录,并寻找优化的解决方案
I have a table like below:
https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=9bb88e4b8ac981eb9cfabb13848a79b9
The expected result is below:
https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=04932c1f5d6f49349a49aac63f51c78a
Here T1 is last month, T2 is last to last month, T3 is 3 months back from now and so on.
TOTAL_INACTIVITY = Total number of months where the amount is 0
MAX_CONSECUTIVE_INACTIVITY = Maximum number of consecutive months where the amount is zero
RECENT_INACTIVITY = Maximum number of consecutive months starting from the recent month i.e T1 and going backward where the amount is 0. That means if T1 has any value except zero, RECENT_INACTIVITY will be zero. For example, person_id 5555 has RECENT_INACTIVITY = 4 since T1_Amount,T2_Amount,T3_Amount and T4_Amount are all 0.
NB: I have around 10 million records and looking for an optimized solution
发布评论
评论(1)
您可以使用
案例
表达式:对于示例数据,输出:
db<>> fiddle here
You can use
CASE
expressions:Which, for the sample data, outputs:
db<>fiddle here