Divided Operator

  • How do we implement DIVIDE OPERATOR in SQL?

  • What are you trying to do? More information is neccessary.

    Eli

  • If you meant the math division operator then you use "/".

  • 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)

  • still not clear to me either, can you give a non-pseudo code, concrete example of the expected results?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • 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.


    And then again, I might be wrong ...
    David Webb

  • 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.

  • 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