dbTalk Databases Forums  

Computing percentage change between tables

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Computing percentage change between tables in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
novice82
 
Posts: n/a

Default Computing percentage change between tables - 07-20-2009 , 03:35 AM






Hi,

I'm a novice to sql scripting. Am trying to figure out a design
problem, involving some arithmatic computation.

I have two tables temp1 and temp2 with two feilds
account no., ( Common in both tables )
balance ( float data type ).

1. I want to compare the balance feilds in temp1 and temp2.
print out the no. of accounts and percentage of match and mismatch.
2. output the a/c nos. whose balances dont match into a seperate
table..

another question, that I have is, how does sql handle the computation,
if a value in a particular field is divided by 0 ?

any help, will get me started.

thanks

Reply With Quote
  #2  
Old   
Álvaro G. Vicario
 
Posts: n/a

Default Re: Computing percentage change between tables - 07-20-2009 , 04:14 AM






novice82 escribió:
Quote:
another question, that I have is, how does sql handle the computation,
if a value in a particular field is divided by 0 ?
It raises a ORA-01476 error ("divisor is equal to zero"). You can test
it yourself:

SELECT 1/0
FROM DUAL


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--

Reply With Quote
  #3  
Old   
Ed Prochak
 
Posts: n/a

Default Re: Computing percentage change between tables - 07-20-2009 , 11:40 AM



On Jul 20, 4:35*am, novice82 <novic... (AT) gmail (DOT) com> wrote:
Quote:
Hi,

I'm a novice to sql scripting. Am trying to figure out a design
problem, involving some arithmatic computation.

I have two tables temp1 and temp2 with two feilds
account no., ( Common in both tables )
balance ( float data type ).

1. I want to compare the balance feilds in temp1 and temp2.
print out the no. of accounts and percentage of match and mismatch.
2. output the a/c nos. whose balances dont match into a seperate
table..

another question, that I have is, how does sql handle the computation,
if a value in a particular field is divided by 0 ?

any help, will get me started.

thanks
the first thing you need to type is:

SELECT



Now really, the question is what have you tried?
Exactly what knowledge of SQL do you have?
(I have seen a SQL for Dummies book,
I've actually opened a SQL for Dummies book,
I have read a SQL for Dummies book,
I have seen the Oracle web page,
I have seen the Oracle SQL web pages,
I have read some of the Oracle SQL web pages, ...)

We do not have the time or space to give a course in SQL in the
newsgroup. Help us help you.

Ed

Reply With Quote
  #4  
Old   
joel garry
 
Posts: n/a

Default Re: Computing percentage change between tables - 07-20-2009 , 01:47 PM



On Jul 20, 9:40*am, Ed Prochak <edproc... (AT) gmail (DOT) com> wrote:
Quote:
On Jul 20, 4:35*am, novice82 <novic... (AT) gmail (DOT) com> wrote:



Hi,

I'm a novice to sql scripting. Am trying to figure out a design
problem, involving some arithmatic computation.

I have two tables temp1 and temp2 with two feilds
account no., ( Common in both tables )
balance ( float data type ).

1. I want to compare the balance feilds in temp1 and temp2.
print out the no. of accounts and percentage of match and mismatch.
Try something. You might want to search the docs at tahiti.oracle.com
for the outer join syntax to account for the case of missing rows.

Quote:
2. output the a/c nos. whose balances dont match into a seperate
table..
When you figure out the syntax, you can do something like create table
dontmatch as select <some fields> from <what you figured out>

Quote:
another question, that I have is, how does sql handle the computation,
if a value in a particular field is divided by 0 ?
What are the business rules for such a situation?

JEG@TTST> select 1/0 from dual;
select 1/0 from dual
*
ERROR at line 1:
ORA-01476: divisor is equal to zero


JEG@TTST> select 1/decode('0',0,'100') from dual;

1/DECODE('0',0,'100')
---------------------
.01

Quote:
any help, will get me started.

thanks

the first thing you need to type is:

SELECT

Now really, the question is what have you tried?
*Exactly what knowledge of SQL do you have?
*(I have seen a SQL for Dummies book,
*I've actually opened a SQL for Dummies book,
*I have read a SQL for Dummies book,
*I have seen the Oracle web page,
*I have seen the Oracle SQL web pages,
*I have read some of the Oracle SQL web pages, ...)
LOL! Oracle Purity test!

Quote:
We do not have the time or space to give a course in SQL in the
newsgroup. Help us help you.

Ed
jg
--
@home.com is bogus.
http://www.bofh.net/sl_Purity.html

Reply With Quote
  #5  
Old   
novice82
 
Posts: n/a

Default Re: Computing percentage change between tables - 07-21-2009 , 03:13 AM



On Jul 20, 5:14*pm, "Álvaro G. Vicario"
<alvaro.NOSPAMTH... (AT) demogracia (DOT) com.invalid> wrote:
Quote:
novice82 escribió:

another question, that I have is, how does sql handle the computation,
if a value in a particular field is divided by 0 ?

It raises a ORA-01476 error ("divisor is equal to zero"). You can test
it yourself:

SELECT 1/0
FROM DUAL

--
--http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://borrame.com
-- Mi web de humor satinado:http://www.demogracia.com
--
Hi,

I tried the following :

SELECT T1.AcountNo, T1.Balance, T2.Balance, T1.Balance/CASE T2.Balance
WHEN 0 THEN NULL END)
FROM Temp1 T1, Temp2 T2
WHERE T1.AccountNo = T2.AccountNo
AND ((T1.Balance / T2.Balance > 1.1)
OR (T1.Balance / T2.Balance < 0.9))

But i'm still unable to circumvent the zero divisor problem.

Any help, will be appreciated.

thanks

Reply With Quote
  #6  
Old   
Álvaro G. Vicario
 
Posts: n/a

Default Re: Computing percentage change between tables - 07-21-2009 , 04:15 AM



novice82 escribió:
Quote:
On Jul 20, 5:14 pm, "Álvaro G. Vicario"
alvaro.NOSPAMTH... (AT) demogracia (DOT) com.invalid> wrote:
novice82 escribió:

another question, that I have is, how does sql handle the computation,
if a value in a particular field is divided by 0 ?
It raises a ORA-01476 error ("divisor is equal to zero"). You can test
it yourself:

SELECT 1/0
FROM DUAL

Quote:
I tried the following :

SELECT T1.AcountNo, T1.Balance, T2.Balance, T1.Balance/CASE T2.Balance
WHEN 0 THEN NULL END)
FROM Temp1 T1, Temp2 T2
WHERE T1.AccountNo = T2.AccountNo
AND ((T1.Balance / T2.Balance > 1.1)
OR (T1.Balance / T2.Balance < 0.9))

But i'm still unable to circumvent the zero divisor problem.
You have to fix it in all the divisions, not only the SELECT clause.





--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--

Reply With Quote
  #7  
Old   
Álvaro G. Vicario
 
Posts: n/a

Default Re: Computing percentage change between tables - 07-21-2009 , 04:19 AM



Álvaro G. Vicario escribió:
Quote:
novice82 escribió:
On Jul 20, 5:14 pm, "Álvaro G. Vicario"
alvaro.NOSPAMTH... (AT) demogracia (DOT) com.invalid> wrote:
novice82 escribió:

another question, that I have is, how does sql handle the computation,
if a value in a particular field is divided by 0 ?
It raises a ORA-01476 error ("divisor is equal to zero"). You can test
it yourself:

SELECT 1/0
FROM DUAL


I tried the following :

SELECT T1.AcountNo, T1.Balance, T2.Balance, T1.Balance/CASE T2.Balance
WHEN 0 THEN NULL END)
FROM Temp1 T1, Temp2 T2
WHERE T1.AccountNo = T2.AccountNo
AND ((T1.Balance / T2.Balance > 1.1)
OR (T1.Balance / T2.Balance < 0.9))

But i'm still unable to circumvent the zero divisor problem.

You have to fix it in all the divisions, not only the SELECT clause.
.... though in this case I suppose you could just remove the rows where
T2.Balance is zero; after all, the other conditions filter them out anyway:

WHERE T1.AccountNo = T2.AccountNo
AND T2.Balance<>0
AND ((T1.Balance / T2.Balance > 1.1)
OR (T1.Balance / T2.Balance < 0.9))



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--

Reply With Quote
  #8  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: Computing percentage change between tables - 07-21-2009 , 04:28 AM



Álvaro G. Vicario schrieb:
Quote:
Álvaro G. Vicario escribió:
novice82 escribió:
On Jul 20, 5:14 pm, "Álvaro G. Vicario"
alvaro.NOSPAMTH... (AT) demogracia (DOT) com.invalid> wrote:
novice82 escribió:

another question, that I have is, how does sql handle the computation,
if a value in a particular field is divided by 0 ?
It raises a ORA-01476 error ("divisor is equal to zero"). You can test
it yourself:

SELECT 1/0
FROM DUAL


I tried the following :

SELECT T1.AcountNo, T1.Balance, T2.Balance, T1.Balance/CASE T2.Balance
WHEN 0 THEN NULL END)
FROM Temp1 T1, Temp2 T2
WHERE T1.AccountNo = T2.AccountNo
AND ((T1.Balance / T2.Balance > 1.1)
OR (T1.Balance / T2.Balance < 0.9))

But i'm still unable to circumvent the zero divisor problem.

You have to fix it in all the divisions, not only the SELECT clause.

... though in this case I suppose you could just remove the rows where
T2.Balance is zero; after all, the other conditions filter them out anyway:

WHERE T1.AccountNo = T2.AccountNo
AND T2.Balance<>0
AND ((T1.Balance / T2.Balance > 1.1)
OR (T1.Balance / T2.Balance < 0.9))



That would not necessarily eliminate the division exception due to
arbitrary evaluation order of predicates. Better imho is to eliminate
division itself

and (t1.balance > 1.1 * t2.balance ...

Best regards

Maxim

--
Why make things difficult, when it is possible to make them cryptic
and totally illogical, with just a little bit more effort?

Aksel Peter Jørgensen

Reply With Quote
  #9  
Old   
novice82
 
Posts: n/a

Default Re: Computing percentage change between tables - 07-22-2009 , 08:13 PM



On Jul 21, 5:28*pm, Maxim Demenko <mdeme... (AT) gmail (DOT) com> wrote:
Quote:
Álvaro G. Vicario schrieb:



Álvaro G. Vicario escribió:
novice82 escribió:
On Jul 20, 5:14 pm, "Álvaro G. Vicario"
alvaro.NOSPAMTH... (AT) demogracia (DOT) com.invalid> wrote:
novice82 escribió:

another question, that I have is, how does sql handle the computation,
if a value in a particular field is divided by 0 ?
It raises a ORA-01476 error ("divisor is equal to zero"). You can test
it yourself:

SELECT 1/0
FROM DUAL

I tried the following :

SELECT T1.AcountNo, T1.Balance, T2.Balance, T1.Balance/CASE T2.Balance
WHEN 0 THEN NULL END)
FROM Temp1 T1, Temp2 T2
WHERE T1.AccountNo = T2.AccountNo
AND ((T1.Balance / T2.Balance > 1.1)
OR (T1.Balance / T2.Balance < 0.9))

But i'm still unable to circumvent the zero divisor problem.

You have to fix it in all the divisions, not only the SELECT clause.

... though in this case I suppose you could just remove the rows where
T2.Balance is zero; after all, the other conditions filter them out anyway:

WHERE T1.AccountNo = T2.AccountNo
AND T2.Balance<>0
AND ((T1.Balance / T2.Balance > 1.1)
OR (T1.Balance / T2.Balance < 0.9))

That would not necessarily eliminate the division exception due to
arbitrary evaluation order of predicates. Better imho is to eliminate
division itself

and (t1.balance > 1.1 * t2.balance ...

Best regards

Maxim

--
Why make things difficult, when it is possible to make them cryptic
and totally illogical, with just a little bit more effort?

Aksel Peter Jørgensen
Thanks a lot.

That works like a charm!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.