Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: boolean logic expressed in RDBMS rows

Re: boolean logic expressed in RDBMS rows

From: M.N. <balkanboy_at_hotmail.com>
Date: 15 May 2003 16:30:05 -0700
Message-ID: <955aa198.0305151530.207afee@posting.google.com>


Correct- what is the algorithm called to convert any boolean expression into disjunctive canonical form? :)

71062.1056_at_compuserve.com (--CELKO--) wrote in message news:<c0d87ec0.0305121642.64e2f67b_at_posting.google.com>...
> >> How about this idea? Express each conditions by EXISTS(correlated
> subquery), then AND/OR each EXISTS(). <<
>
> I think what he is after is the ability to load tables with criteria
> and not have to use dynamic SQL:
>
> skill = Java AND (skill = Perl OR skill = PHP)
>
> becomes the disjunctive canonical form:
>
> (Java AND Perl) OR (Java AND PHP)
>
> which we load into this table:
>
> CREATE TABLE Query
> (and_grp INTEGER NOT NULL,
> skill CHAR(4) NOT NULL,
> PRIMARY KEY (and_grp, skill));
>
> INSERT INTO Query VALUES (1, 'Java');
> INSERT INTO Query VALUES (1, 'Perl');
> INSERT INTO Query VALUES (2, 'Java');
> INSERT INTO Query VALUES (2, 'PHP');
>
> Assume we have a table of job candidates:
>
> CREATE TABLE Candidates
> (candidate_name CHAR(15) NOT NULL,
> skill CHAR(4) NOT NULL,
> PRIMARY KEY (candidate_name, skill));
>
> INSERT INTO Candidates VALUES ('John', 'Java'); --winner
> INSERT INTO Candidates VALUES ('John', 'Perl');
> INSERT INTO Candidates VALUES ('Mary', 'Java'); --winner
> INSERT INTO Candidates VALUES ('Mary', 'PHP');
> INSERT INTO Candidates VALUES ('Larry', 'Perl'); --winner
> INSERT INTO Candidates VALUES ('Larry', 'PHP');
> INSERT INTO Candidates VALUES ('Moe', 'Perl'); --winner
> INSERT INTO Candidates VALUES ('Moe', 'PHP');
> INSERT INTO Candidates VALUES ('Moe', 'Java');
> INSERT INTO Candidates VALUES ('Celko', 'Java'); -- loser
> INSERT INTO Candidates VALUES ('Celko', 'Algol');
> INSERT INTO Candidates VALUES ('Smith', 'APL'); -- loser
> INSERT INTO Candidates VALUES ('Smith', 'Algol');
>
> The query is simple now:
>
> SELECT DISTINCT C1.candidate_name
> FROM Candidates AS C1, Query AS Q1
> WHERE C1.skill = Q1.skill
> GROUP BY Q1.and_grp, C1.candidate_name
> HAVING COUNT(C1.skill)
> = (SELECT COUNT(*) FROM Query AS Q2 WHERE Q1.and_grp =
> Q2.and_grp);
>
> You can retain the COUNT() information to rank candidates. For
> example Moe meets both qualifications, while other candidates meet
> only one of the two.
Received on Thu May 15 2003 - 18:30:05 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US