Author |
Topic |
nt4vn
Yak Posting Veteran
98 Posts |
Posted - 2008-06-18 : 10:27:13
|
Please help me how to write a code to eliminate duplicated balance on report. Here the data:Account1: 111-222-3333Balance: 1,7,426.98 (it repeated in the database for 3 different day: For example: - On 05/05/2008, balance listed = 1,742,698 - One 06/18/2008, balance listed = 1,742,698 - On 06/15/2008, balance listed = 1,742,698I used sum(balance), then it total all 3, but it should be one balance = 1,742,698Anyone could help..thanks, |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-18 : 10:28:50
|
may be sum(distinct balance) |
 |
|
nt4vn
Yak Posting Veteran
98 Posts |
Posted - 2008-06-18 : 10:32:03
|
quote: Originally posted by visakh16 may be sum(distinct balance)
I tried, but it does not work. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-06-18 : 10:33:04
|
Try setting "Ignore duplicate row" option in reporting engine. E 12°55'05.25"N 56°04'39.16" |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-18 : 10:46:02
|
Can you provide sample dataset? |
 |
|
nt4vn
Yak Posting Veteran
98 Posts |
Posted - 2008-06-18 : 10:58:50
|
quote: Originally posted by visakh16 Can you provide sample dataset?
ID Balance DAF_DATE111222333 150000.00 2008-05-12111222333 162000.00 2008-06-02111222333 162000.00 2008-06-02111222333 0.00 2008-06-02111222333 0.00 2008-06-02111222333 162000.00 2008-06-02Thanks, I am thinking of using max function ex: max(balance)....to get the maximum balance |
 |
|
jdaman
Constraint Violating Yak Guru
354 Posts |
Posted - 2008-06-18 : 11:01:19
|
Are you after the maximum balance or the most recent balance? |
 |
|
nt4vn
Yak Posting Veteran
98 Posts |
Posted - 2008-06-18 : 11:05:26
|
quote: Originally posted by jdaman Are you after the maximum balance or the most recent balance?
That was what I thought...but not sure if that is right... |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-18 : 11:07:03
|
quote: Originally posted by nt4vn
quote: Originally posted by visakh16 Can you provide sample dataset?
ID Balance DAF_DATE111222333 150000.00 2008-05-12111222333 162000.00 2008-06-02111222333 162000.00 2008-06-02111222333 0.00 2008-06-02111222333 0.00 2008-06-02111222333 162000.00 2008-06-02Thanks, I am thinking of using max function ex: max(balance)....to get the maximum balance
How did duplicate records come for same day with different balance values? What's your business rule for this case? You need to just take any one of non zero balance? Is there a chance where there can be multiple non zero balances for same day? |
 |
|
jdaman
Constraint Violating Yak Guru
354 Posts |
Posted - 2008-06-18 : 11:08:03
|
This will give you the most recent maximum balance:select a.ID, max(a.Balance) as Balancefrom YourTable ajoin ( select ID, max(DAF_DATE) as DAF_DATE from YourTable group by ID ) b on a.ID = b.ID and a.DAF_DATE = b.DAF_DATEgroup by a.ID |
 |
|
nt4vn
Yak Posting Veteran
98 Posts |
Posted - 2008-06-18 : 11:35:14
|
quote: Originally posted by visakh16
quote: Originally posted by nt4vn
quote: Originally posted by visakh16 Can you provide sample dataset?
ID Balance DAF_DATE TYPE111222333 150000.00 2008-05-12 O111222333 162000.00 2008-06-02 S111222333 162000.00 2008-06-02 S111222333 0.00 2008-06-02 0111222333 0.00 2008-06-02 0111222333 162000.00 2008-06-02 SThanks, I am thinking of using max function ex: max(balance)....to get the maximum balance
How did duplicate records come for same day with different balance values? What's your business rule for this case? You need to just take any one of non zero balance? Is there a chance where there can be multiple non zero balances for same day?
Actually there is a type for these transaction that I just found out. Two types: o=original, s=supllemental. So I was confirm to go with max(balance)with type=s. Thanks, (SEE I ADD ANOTHER COLUMN 'TYPE' FOR DATA EXAMPLE. |
 |
|
jdaman
Constraint Violating Yak Guru
354 Posts |
Posted - 2008-06-18 : 11:39:22
|
quote: Originally posted by nt4vnActually there is a type for these transaction that I just found out. Two types: o=original, s=supllemental. So I was confirm to go with max(balance)with type=s. Thanks, (SEE I ADD ANOTHER COLUMN 'TYPE' FOR DATA EXAMPLE.
Would the correct amount then be the original transaction amount plus any supplement transactions for a given date or are you only after the original amount? |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-18 : 11:51:56
|
quote: Originally posted by nt4vn
quote: Originally posted by visakh16
quote: Originally posted by nt4vn
quote: Originally posted by visakh16 Can you provide sample dataset?
ID Balance DAF_DATE TYPE111222333 150000.00 2008-05-12 O111222333 162000.00 2008-06-02 S111222333 162000.00 2008-06-02 S111222333 0.00 2008-06-02 0111222333 0.00 2008-06-02 0111222333 162000.00 2008-06-02 SThanks, I am thinking of using max function ex: max(balance)....to get the maximum balance
How did duplicate records come for same day with different balance values? What's your business rule for this case? You need to just take any one of non zero balance? Is there a chance where there can be multiple non zero balances for same day?
Actually there is a type for these transaction that I just found out. Two types: o=original, s=supllemental. So I was confirm to go with max(balance)with type=s. Thanks, (SEE I ADD ANOTHER COLUMN 'TYPE' FOR DATA EXAMPLE.
So whats balance you're looking at/ Original ones or supplemented ones or sum of all? |
 |
|
nt4vn
Yak Posting Veteran
98 Posts |
Posted - 2008-06-18 : 22:34:09
|
quote: Originally posted by visakh16
quote: Originally posted by nt4vn
quote: Originally posted by visakh16
quote: Originally posted by nt4vn
quote: Originally posted by visakh16 Can you provide sample dataset?
ID Balance DAF_DATE TYPE111222333 150000.00 2008-05-12 O111222333 162000.00 2008-06-02 S111222333 162000.00 2008-06-02 S111222333 0.00 2008-06-02 0111222333 0.00 2008-06-02 0111222333 162000.00 2008-06-02 SThanks, I am thinking of using max function ex: max(balance)....to get the maximum balance
How did duplicate records come for same day with different balance values? What's your business rule for this case? You need to just take any one of non zero balance? Is there a chance where there can be multiple non zero balances for same day?
Actually there is a type for these transaction that I just found out. Two types: o=original, s=supllemental. So I was confirm to go with max(balance)with type=s. Thanks, (SEE I ADD ANOTHER COLUMN 'TYPE' FOR DATA EXAMPLE.
So whats balance you're looking at/ Original ones or supplemented ones or sum of all?
I will be using the supplemented ones. |
 |
|
nt4vn
Yak Posting Veteran
98 Posts |
Posted - 2008-06-18 : 22:36:13
|
quote: Originally posted by jdaman
quote: Originally posted by nt4vnActually there is a type for these transaction that I just found out. Two types: o=original, s=supllemental. So I was confirm to go with max(balance)with type=s. Thanks, (SEE I ADD ANOTHER COLUMN 'TYPE' FOR DATA EXAMPLE.
Would the correct amount then be the original transaction amount plus any supplement transactions for a given date or are you only after the original amount?
With the above data example, $162000 is the right amount I suppose to take. Thanks, |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-19 : 02:46:23
|
quote: Originally posted by nt4vn
quote: Originally posted by jdaman
quote: Originally posted by nt4vnActually there is a type for these transaction that I just found out. Two types: o=original, s=supllemental. So I was confirm to go with max(balance)with type=s. Thanks, (SEE I ADD ANOTHER COLUMN 'TYPE' FOR DATA EXAMPLE.
Would the correct amount then be the original transaction amount plus any supplement transactions for a given date or are you only after the original amount?
With the above data example, $162000 is the right amount I suppose to take. Thanks,
may be this SUM(DISTINCT CASE WHEN TYPE='S' THEN Balance ELSE 0 END) |
 |
|
|