[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1394
  • 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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

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