Re: Curious SQL question

From: Jay Dee <ais01479_at_aeneas.net>
Date: Thu, 04 Jan 2007 04:49:29 GMT
Message-ID: <tH%mh.6945$SJ3.6319_at_tornado.ohiordc.rr.com>


Neo wrote:

>>Products (ID, Name)
>>Orders (Customer_ID, Product_ID)
>>
>>How can I find out what products, each customer DIDN'T bought?
To answer this question, I would expect a set of {customer, product} in which no values for customers who bought all products appear; that's very different from the set of {product} which no one bought.

How often we believe we know what was wanted despite what was asked for...

> Below is an alternate partial solution using dbd. John orders shampoo
> and soap. Mary orders soap and bread. No one orders wine. Queries
> returns what products John, Mary and any person did not order.
>
> (new 'order 'verb)
>
> (new 'shampoo 'product)
> (new 'soap 'product)
> (new 'bread 'product)
> (new 'wine 'product)
>
> (new 'john 'person)
> (set john order shampoo)
> (set john order soap)
>
> (new 'mary 'person)
> (set mary order soap)
> (set mary order bread)
>
> (; Get products not ordered by john)
> (; Gets bread and wine)
> (!= (get product instance *)
> (get john order *))
>
> (; Get products not ordered by mary)
> (; Gets shampoo and wine)
> (!= (get product instance *)
> (get mary order *))
>
> (; Get products not ordered by any person)
> (; Gets wine)
> (!= (get product instance *)
> (get (get person instance *) order *))
>
Received on Thu Jan 04 2007 - 05:49:29 CET

Original text of this message