Solved

Division operator in SQL

Posted on 2004-09-14
15
1,347 Views
Last Modified: 2008-01-09
Hello All,

   Could you please help me in obtaining the result of division operator using other basic operators available in SQL with examples? And division operator is not available in SQL as it is redundant operator.

Thanks in Advance.
Regards,
Neeraja
0
Comment
Question by:NeerajaR
  • 3
  • 3
  • 3
  • +3
15 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 12052821
Hello NeerajaR,

Which SQL dialect are you using? (Oracle? T_Sql/Sql Server/ Jet / MySql... which?)


Pete
0
 

Author Comment

by:NeerajaR
ID: 12052830
Hello Peter,

  It is Oracle.

Regards,
Neeraja
0
 
LVL 77

Expert Comment

by:peter57r
ID: 12052966
Why do think you cannot use a standard division symbol?  (/)

Pete
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 12053462
homework?

Actually, maths prove that  a/b = 2^( log2 ( a ) - log2 (b) )
in oracle, the functions are called EXP and LN (resp. LOG), the rest should be your work...

CHeers
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12053479
take care with division, to take care of divide-by-zero...

SQL> CREATE TABLE test_table( a number, b number );

Table created.

SQL> INSERT INTO test_table VALUES( 1, 0 );

1 row created.

SQL> INSERT INTO test_table VALUES( 1, 2 );

1 row created.

SQL> SELECT a/b FROM test_table;
SELECT a/b FROM test_table
        *
ERROR at line 1:
ORA-01476: divisor is equal to zero


SQL> SELECT a/DECODE(b,0,null,b) FROM test_table;

A/DECODE(B,0,NULL,B)
--------------------

                  .5

0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 12053483
another one (more simple):
a/b = a * b^(-1)
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 18

Expert Comment

by:SjoerdVerweij
ID: 12055879
Smells like homework to me...
0
 
LVL 9

Expert Comment

by:solution46
ID: 12057694
or maybe a bit of teen spirit :)
0
 
LVL 9

Expert Comment

by:solution46
ID: 12057697
or does that assume that EE is a true nirvana?
0
 
LVL 18

Expert Comment

by:SjoerdVerweij
ID: 12058193
Okay, that's enough puns for one thread!
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 12703420
I think I have given 2 clear indications of what the solution should be (without giving the full answer at it smelled homework)...
0
 
LVL 18

Expert Comment

by:SjoerdVerweij
ID: 12708005
Is there a way to do the right thing here: give angelIII the points AND throw this question away? :-)
0
 
LVL 9

Expert Comment

by:solution46
ID: 12719209
I agree with SV. Interesting maths, if nothing else!

s46.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
spx for moving values to new table 5 70
Stop the possibility of taking backup in MySQL on Ubuntu 1 74
Client backup and data retention? 3 56
append to an ms access field 6 26
Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now