Home » SQL & PL/SQL » SQL & PL/SQL » Aggregate based on serial number after checking for thresholds
Aggregate based on serial number after checking for thresholds [message #652830] Mon, 20 June 2016 12:08 Go to next message
ketangarg86
Messages: 3
Registered: March 2015
Junior Member
Hi Guys,

I am relatively new to SQL oracle and need your help.

I have a table which has the following columns
Type, Serial Number, Principal, Loan Amount and Date (sample below)

Type	Serial Number	Principal	Loan Amount	Date
TEST	12345	        17.58704	18	                June 20th
TEST	12345		                18.1	                June 20th
TEST	12345		                180	                June 20th
TEST	12345		                18	                June 20th
TEST	12345	        17.587	18	                June 20th
TEST	12345		                17.9	                June 21st
TEST	12345		                18	                June 21st
TEST	12345		                18	                June 21st

Now I want to aggregate principal and loan amount based on serial number and type for any given day. Serial number and type relationship is one to one.

A few issues, I am having
1. I dont want to double count the principal or loan amount
2. To account for typo entries in data entry, I want to exclude the entry where there is a factor of more than 10 (example loan amount of 180 in above sample data). Now this exclusion is based on the majority of the rows falling in the same range on a particular date. If there is only one row for a unique serial number it is fine. If there are two, then exclude both if there is a factor of more than 10. If there are three, then take the majority.
3. So if the principal for a particular serial number/type combination on a given day is under 10% threshold of each other, I would want to take an average of them and treat as one. Same goes for the loan amount.
4. For point 3, if the threshold is more than 10% then aggregate the data (this is under the assumption that step 2 will already clean up the data).


[mod-edit: code tags added by bb]

[Updated on: Mon, 20 June 2016 15:59] by Moderator

Report message to a moderator

Re: Aggregate based on serial number after checking for thresholds [message #652831 is a reply to message #652830] Mon, 20 June 2016 12:12 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://www.orafaq.com/forum/mv/msg/197093/636097/#msg_636097
Re: Aggregate based on serial number after checking for thresholds [message #652832 is a reply to message #652830] Mon, 20 June 2016 12:14 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
I see that you have posted questions here before, but that you never acknowledged the help you were offered.
You have also ignored the request to format your posts properly, and to follow the forum guidelines:

Please read our OraFAQ Forum Guide and How to use [code] tags and make your code easier to read

For this question, you should provide the CREATE TABLE sttements and the eighr INSER statements, and the SELECTs rthat you have tried s far.
Re: Aggregate based on serial number after checking for thresholds [message #652835 is a reply to message #652830] Mon, 20 June 2016 13:06 Go to previous message
Michel Cadot
Messages: 68647
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

From your previous topics:

BlackSwan wrote on Thu, 12 March 2015 16:27
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and read http://www.orafaq.com/forum/t/174502/


BlackSwan wrote on Thu, 16 April 2015 20:59
http://www.orafaq.com/forum/mv/msg/196730/634654/#msg_634654


Michel Cadot wrote on Thu, 16 April 2015 21:54

Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Also always post your Oracle version, with 4 decimals.

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.


In addition, feedback to your topics if not thank people to spend time to read your questions and help you.

Previous Topic: Exception Handling
Next Topic: how to export the data from table to the file
Goto Forum:
  


Current Time: Fri Apr 26 17:43:03 CDT 2024