Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: rbeliz000Looking for best way to perform a math function between two records in a table.
Please reference the two tables below for additional information.
• Table A represents original static table
• Table B represents the desired end product
Referencing the first 2 records in table B:
You’ll note I am performing a subtract function between the first two records to get the difference column of 10.
Logic =
If account number is the same, subtract older revenue date from newer revenue date.
Additional notes:
• the below tables have mock data however data type is identical
• actual tables will have 2-3 million records
• output will need to have an adjustable parameter in the difference column. i.e. only output records which have a difference of > 10.
Any guidance or suggestion on the best way to perform this in Brain would be greatly appreciated.
Thanks,
RB
Table A
ACCOUNT_NUMBER REVENUE_AMT REV_DATE COUNT
002210532 46.99 3/15/2012 2
002210532 56.99 3/16/2012 2
870050232 155.8 3/11/2012 2
870050232 138.85 3/13/2012 2
871570132 106.94 3/12/2012 2
871570132 123.89 3/16/2012 2
874440232 96.94 3/16/2012 2
874440232 113.89 3/17/2012 2
877270232 74.99 3/11/2012 2
877270232 54.95 3/12/2012 2
895150232 141.89 3/11/2012 3
895150232 131.89 3/14/2012 3
895150232 139.85 3/16/2012 3
910730132 71.9 3/1/2012 3
910730132 126.9 3/13/2012 3
910730132 143.85 3/14/2012 3
910800132 36.99 3/15/2012 2
910800132 31.99 3/16/2012 2
914500132 29.99 3/11/2012 2
914500132 33.97 3/12/2012 2
915090132 66.94 3/14/2012 2
915090132 85.93 3/17/2012 2
Table B
ACCOUNT_NUMBER REVENUE_AMT REV_DATE COUNT DIFFERENCE
002210532 46.99 3/15/2012 2
002210532 56.99 3/16/2012 2 10
870050232 155.8 3/11/2012 2
870050232 138.85 3/13/2012 2 -16.95
871570132 106.94 3/12/2012 2
871570132 123.89 3/16/2012 2 16.95
874440232 96.94 3/16/2012 2
874440232 113.89 3/17/2012 2 16.95
877270232 74.99 3/11/2012 2
877270232 54.95 3/12/2012 2 -20.04
895150232 141.89 3/11/2012 3
895150232 131.89 3/14/2012 3 -10
895150232 139.85 3/16/2012 3 7.96
910730132 71.9 3/1/2012 3
910730132 126.9 3/13/2012 3 55
910730132 143.85 3/14/2012 3 16.95
910800132 36.99 3/15/2012 2
910800132 31.99 3/16/2012 2 -5
914500132 29.99 3/11/2012 2
914500132 33.97 3/12/2012 2 3.98
915090132 66.94 3/14/2012 2
915090132 85.93 3/17/2012 2 18.99