Hello,
I was working for a telecom company some years ago and I had to generate a formula which calculates duration of a call according to the following algorithm:
- t1 is the first period
- t2 is the recurring period
- RCT is the actual call time (in seconds)
- CD is the effective call duration (for billing purposes)
if RCT is less than t1, then the CD equals t1
if RCT is greater than t1, then CD = t1 + x*t2, where x will "round" RCT to the next highest multiple of t2.
This algorithm translates to: "Charge for the first t1 seconds, then charge every t2 seconds after that".
Example:
t1 t2 RCT CD
60 10 48 60
60 10 65 70
60 10 121 130
30 20 25 30
30 20 35 50
30 20 65 70
Can you create a function / SQL that will return the "call duration" CD?
Without using if then else ...?