Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1395
  • Last Modified:

Division operator in SQL

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
NeerajaR
Asked:
NeerajaR
  • 3
  • 3
  • 3
  • +3
1 Solution
 
peter57rCommented:
Hello NeerajaR,

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


Pete
0
 
NeerajaRAuthor Commented:
Hello Peter,

  It is Oracle.

Regards,
Neeraja
0
 
peter57rCommented:
Why do think you cannot use a standard division symbol?  (/)

Pete
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
cjjcliffordCommented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
another one (more simple):
a/b = a * b^(-1)
0
 
SjoerdVerweijCommented:
Smells like homework to me...
0
 
solution46Commented:
or maybe a bit of teen spirit :)
0
 
solution46Commented:
or does that assume that EE is a true nirvana?
0
 
SjoerdVerweijCommented:
Okay, that's enough puns for one thread!
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I think I have given 2 clear indications of what the solution should be (without giving the full answer at it smelled homework)...
0
 
SjoerdVerweijCommented:
Is there a way to do the right thing here: give angelIII the points AND throw this question away? :-)
0
 
solution46Commented:
I agree with SV. Interesting maths, if nothing else!

s46.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

  • 3
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now