dbTalk Databases Forums  

How to find persons who like red fruits or crunchy veggies?

comp.databases comp.databases


Discuss How to find persons who like red fruits or crunchy veggies? in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Neo
 
Posts: n/a

Default Re: How to find persons who like red fruits or crunchy veggies? - 11-16-2006 , 11:27 PM






Quote:
find pilots that can fly all airplanes
Following example finds pilots that fly all jets using selectAll
function.

(new 'fly 'verb)

(new 'jet1 'jet)
(new 'jet2 'jet)

(new 'pilot1 'pilot)
(create pilot1 fly jet1)

(new 'pilot2 'pilot)
(create pilot2 fly jet1)
(create pilot2 fly jet2)

(; Find pilots who fly all jets)
(; Finds pilot2)
(and (select pilot instance *)
(selectAll * fly (select jet instance *)))

(new 'jet3 'jet)
(new 'pilot3 'pilot)
(create pilot3 fly jet1)
(create pilot3 fly jet2)
(create pilot3 fly jet3)

(; Find pilots who fly all jets)
(; Finds pilot3)
(and (select pilot instance *)
(selectAll * fly (select jet instance *)))

(new 'red 'color)
(create jet1 color red)

(new 'green 'color)
(create jet2 color green)

(new 'blue 'color)
(new 'purple 'color)
(create jet3 color blue)
(create jet3 color purple)

(; Find pilots who fly all jets that are red)
(; Finds pliot1, pilot2 and pilot3)
(and (select pilot instance *)
(selectAll * fly (and (select jet instance *)
(select * color red))))

(; Find pilots who fly all jets that are green)
(; Finds pilot2 and pilot3)
(and (select pilot instance *)
(selectAll * fly (and (select jet instance *)
(select * color green))))

(; Find pilots who fly all jets that are blue and purple)
(; Finds pilot3)
(and (select pilot instance *)
(selectAll * fly (and (select jet instance *)
(select * color blue)
(select * color purple))))

(; Find pilots who fly all jets that are red or green)
(; Finds pilot2 and pilot3)
(and (select pilot instance *)
(selectAll * fly (and (select jet instance *)
(select * color (or red green)))))



Reply With Quote
  #12  
Old   
Neo
 
Posts: n/a

Default Re: How to find persons who like red fruits or crunchy veggies? - 11-17-2006 , 06:10 PM






Quote:
In your language, can you query:
How many fruit colors are there?
Which fruit color(s) is/are the most liked?
How many veggies are there that nobody likes?
An updated example with min, max, sum, avg and count functions.

(; Create qty 28, 30, 35)
(new '25 'quantity)
(new '30 'quantity)
(new '35 'quantity)

(; Create a verb named age)
(new 'age 'verb)

(; Create a person named john whose age is 25)
(new 'john 'person)
(create john age 25)

(; Create a person named mary whose age is 30)
(new 'mary 'person)
(create mary age 30)

(; Create a person named bob whose age is 35)
(new 'bob 'person)
(create bob age 35)

(; Create a person named sue whose age is unknown)
(new 'sue 'person)

(; Count persons)
(; Returns qty instance named 4)
(count (select person instance *))

(; Count persons with age)
(; Returns qty instance named 3)
(count (and (select person instance *)
(select * age)))

(; Get minimum age of persons)
(; Returns qty instance named 25)
(min (select (select person instance *) age *))

(; Get maximum age of persons)
(; Returns qty instance named 35)
(max (select (select person instance *) age *))

(; Get sum of persons age)
(; Returns qty instance named 90)
(sum (select (select person instance *) age *))

(; Get average of persons age)
(; Returns qty instance named 30)
(avg (select (select person instance *) age *))

For details, see www.dbfordummies.com/example/ex045.asp



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.