July 24, 2009 at 4:16 am
How do we implement DIVIDE OPERATOR in SQL?
July 24, 2009 at 12:36 pm
What are you trying to do? More information is neccessary.
Eli
July 24, 2009 at 1:11 pm
If you meant the math division operator then you use "/".
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
July 24, 2009 at 2:08 pm
stopitallready (7/24/2009)
What are you trying to do? More information is neccessary.Eli
I mean 8th operator. A divided by B per C
and A,B and C are result set.
A divided by B per C = A minus ( (A times B) minus C)
July 24, 2009 at 4:54 pm
still not clear to me either, can you give a non-pseudo code, concrete example of the expected results?
Lowell
July 24, 2009 at 5:04 pm
If you're talking about the relational division operator, a decent explanation with some SQL as an example is http://www.dbazine.com/ofinterest/oi-articles/celko1.
I'm not a big Celko fan, but this (and the included references) should get you started.
July 25, 2009 at 3:02 am
Take a look at Vadim Tropashko's book SQL Design Patterns for examples of relational division problems and solutions.
Full marks for a good question by the way. It's a bit unfortunate that Relational Algebra and other relational theory ideas aren't as well appreciated and used in the SQL community as they perhaps ought to be. These concepts give you the tools and a vocabulary for solving lots of every day problems.
Unfortunately, as has often been noted, too many database practitioners today don't know the relational model at all. They just know SQL and someone once told them SQL was relational so they assume they must know the relational stuff too.
Not knocking anyone here BTW. Just my thoughts for this "Relational Theory" forum.
Hope this helps.
July 25, 2009 at 3:36 am
Thank you.
I agree with you. a lot of difficult problem solve by using relational algebra.
Dr. CJ Date offered two methods but I was looking for the best solution for division operator.
here is a method: Please exec following script before exec this query
-- My Method
SELECT DISTINCT pilot
FROM PilotSkills AS PS
WHERE NOT EXISTS (
SELECT plane FROM Hangar
EXCEPT
SELECT plane FROM PilotSkills
WHERE PS.pilot=pilot
)
/*
CREATE TABLE PilotSkills
(pilot CHAR(15) NOT NULL,
plane CHAR(15) NOT NULL,
PRIMARY KEY (pilot, plane));
INSERT INTO PilotSkills
SELECT pilot='Celko', plane='Piper Cub'
UNION
SELECT 'Higgins','B-52 Bomber'
UNION
SELECT 'Higgins','F-14 Fighter'
UNION
SELECT 'Higgins','Piper Cub'
UNION
SELECT 'Jones','B-52 Bomber'
UNION
SELECT 'Jones','F-14 Fighter'
UNION
SELECT 'Smith','B-1 Bomber'
UNION
SELECT 'Smith','B-52 Bomber'
UNION
SELECT 'Smith','F-14 Fighter'
UNION
SELECT 'Wilson','B-1 Bomber'
UNION
SELECT 'Wilson','B-52 Bomber'
UNION
SELECT 'Wilson','F-14 Fighter'
UNION
SELECT 'Wilson','F-17 Fighter'
CREATE TABLE Hangar
(plane CHAR(15) NOT NULL PRIMARY KEY);
INSERT INTO Hangar
SELECT plane='B-1 Bomber'
UNION
SELECT 'B-52 Bomber'
UNION
SELECT 'F-14 Fighter'
*/
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply