![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
------------------------ FeeTier ------------------------ AccountID Tier MinValue MaxValue Fee ------------------------ |
#2
| |||
| |||
|
|
I am trying to find a design pattern/data model pattern for a database problem regarding value ranges/tiers. I actually got this to work a few years ago on my own, but I figured this is likely a scenario that more folks have run into and a standardized solution may exist. Here's the scenario: I need to apply a multi-tiered fee system based on the amount of money held in an account. As the amount of money held in an account goes up, the value of fees applied drop (an incentive to hold more money in the account). I can use business logic to apply the fees, but I need to know how to best store it in a database. I'll use the example of three tiers. 1) The number of tiers can be infinite 2) The first tier can have a min value of "infinite" in negative (if I explained that correctly) 3) The last tier can have a max value of "infinite" in positive My current table schema looks like so: |------------------------ | FeeTier |------------------------ | AccountID | Tier | MinValue | MaxValue | Fee |------------------------ The records for this example would look like so: AccountID | Tier | MinValue | MaxValue | Fee | ------------------------------------------------------------------------| 15 | 1 | $00.00 | $10.99 | $5.00 | 15 | 2 | $11.00 | $20.99 | $3.00 | 15 | 3 | $21.00 | -$01.00 | $1.00 | I use the value of -$01.00 in the MaxValue of Tier 3 to represent "infinity" in that spot. The business logic would have to recognize that anytime a MaxValue has a value of -1, that marks the end of the ranges. You'd have to validate the tier system anytime changes are made, validate the enter range system to make sure each tier's MinValue leaves no gap between it and the previous tier's MaxValue. I have most concern about my design regarding using the -1 value as the MaxValue infinity in the last tier. It seems like I kind of "rigged" it to work, but a more efficient method exists somewhere. |
#3
| |||
| |||
|
|
I have most concern about my design regarding using the -1 value as the MaxValue infinity in the last tier. It seems like I kind of "rigged" it to work, but a more efficient method exists somewhere. |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
Thank you for the responses. I take it that "stepwise continuous function" is the term applied to my problem? I usually avoid using nulls in my database fields because I always seemed to run into problems with them (no need for me to explain, it's due to lack of experience). |
|
But using a null value probable makes the most sense. |
|
------------------------ FeeTier ------------------------ AccountID Tier MinValue MaxValue Fee ------------------------ ------------------------ FeePositiveInfiniteTier ------------------------ AccountID Tier MinValue Fee ------------------------ |
#6
| |||
| |||
|
|
I take it that "stepwise continuous function" is the term applied to my problem? |
|
I usually avoid using nulls in my database fields [sic] because I always seemed to run into problems with them (no need for me to explain, it's due to lack of experience). But using a null value probable makes the most sense. |
#7
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |