Re: Network Example: Sibling of Opposite Gender
Date: 24 Dec 2006 04:16:22 -0800
Message-ID: <1166962582.052073.120780_at_73g2000cwn.googlegroups.com>
Neo wrote:
> Suppose Adam has children named John(male), Jack(male) and Mary(female)
> and we want to find John's sibling of opposite gender without refering
> to John's father (Adam) or John's gender (male) directly. Below is a
> solution using a network-type db. What RMDB schema/query implements the
> equivalent?
>
> (new 'male 'gender)
> (new 'female 'gender)
>
> (new 'opposite 'verb)
> (set male opposite female)
> (set female opposite male)
I feel define opposite is redundant. Because there are only two gender,
it is enough that you look for different gender.
Or, is it difficult to look for different gender on network-type db?
>
> (new 'adam 'person)
>
> (new 'john 'person)
> (set john gender male)
>
> (new 'jack 'person)
> (set jack gender male)
>
> (new 'mary 'person)
> (set mary gender female)
>
> (set adam child john)
> (set adam child jack)
> (set adam child mary)
>
> (; Get john's sibling of opposite gender
> by getting persons
> whose gender is opposite
> and is child of john's parent
> and that person is not himself)
This condition is redundant.
Because you are looking for "(john's sibling of) opposite gender". it
is impossible that he himself has opposite gender. (Or, is he
androgynous? Please take it easy. Just joking.)
> (; Gets mary)
> (!= (and (get person instance *)
> (get * gender (get (get john gender *) opposite *))
> (get (get * child john) child *))
> john)
I can't understand that in where do you think difficulty is.
I feel you,trying to invent new DB other than RDB, should study more
RDB(Especially SQL language) and understand capability of SQL. After
you find weakness or shortcoming of SQL, you should design new DB with
full capability of SQL, without some of shortcoming of SQL and
hopefully having more strong functionality.
Many time I saw samples of dbd. But, as far as samples I saw, they are
easily translated into RDB(SQL).
Note: Please, don't think MS Access is real RDB. It's SQL is too
restrictive.
You shoud consider RDBs are Oracle, DB2, MS SQL Server,
PostgreSQL.(Although, I don't know other RDB. someone knows more)
May be MySQL can be included it. In past it's SQL was also too
restrictive and weak functionality. But, recently it's functionality of
SQL is rapidly growing.
Recently, I saw a sample like this titled "How to find Brothers and
Sisters?"
The problen is
"Suppose Adam has children named John(male), Jack(male) and
Mary(female). What schema/query finds John's brothers and sisters based
only on direct relationships to parent and gender. A direct relationship would be parent/child. An indirect/derived relationship would be brother/sister. The query is not to use Adam directly." That was answed by Cimode. You can find SQL answer of this problem easily by referencing it.
By the way, here is another answer of SQL.(But, I think basically same
idea of Cimode's)
CREATE TABLE person
(name VARCHAR(7) NOT NULL ,gender VARCHAR(6) NOT NULL CHECK(gender IN ('male', 'female')) ,father VARCHAR(7) ,mother VARCHAR(7)
);
INSERT INTO person
VALUES
('adam', 'male', NULL, NULL) ,('john', 'male', 'adam', NULL) ,('jack', 'male', 'adam', NULL) ,('mary', 'female', 'adam', NULL)
(; Get john's sibling of opposite gender
by getting persons
whose gender is opposite
and is child of john's parent
and that person is not himself)
Translate your comment into SQL language will be enough.
------------------------------ Commands Entered ------------------------------ SELECT sibling.name AS "john's sibling" /* of opposite gender */ FROM person john /* (Get) john's ... */ , person sibling /* by getting persons */ WHERE john.name = 'john' /* john's */AND sibling.gender <> john.gender /* whose gender is opposite */ AND sibling.father = john.father /* and is child of john's parent */
-- AND sibling.name <> john.name /* and that person is not himself */
;
john's sibling
mary
1 record(s) selected. Received on Sun Dec 24 2006 - 13:16:22 CET