| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> How to find Brothers and Sisters?
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. Below
is a solution using dbd.
(new 'male 'gender)
(new 'female 'gender)
(new 'adam 'person)
(new 'john 'person)
(set john gender male)
(new 'jack 'person)
(set jack gender male)
(new 'mary 'person)
(set mary gender female)
(new 'child 'verb)
(set adam child john)
(set adam child jack)
(set adam child mary)
(; Get john's brothers
by getting persons
whose gender is male
and is child of john's father
and that person is not himself)
(; Gets jack)
(!= (and (get person instance *)
(get * gender male)
(get (get * child john) child *))
john)
(; Get john's sisters
by getting persons
whose gender is female
and is child of john's father
and that person is not himself)
(; Gets mary)
(!= (and (get person instance *)
(get * gender female)
(get (get * child john) child *))
john)
Received on Fri Dec 01 2006 - 15:01:40 CST
![]() |
![]() |