Re: Curious SQL question

From: Neo <neo55592_at_hotmail.com>
Date: 4 Jan 2007 14:55:12 -0800
Message-ID: <1167951312.159270.192210_at_i15g2000cwa.googlegroups.com>


> > How can I find out what products, each customer DIDN'T bought?
>
> I would expect a set of {customer, product} ...

This dbd solution returns "john not_order bread", "john not_order wine", etc.

(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)

(new 'bob 'person)
(new 'sue 'person)

(; Get products not ordered by any person)
(; Gets wine)
(!= (get product instance *)

     (get (get person instance *) order *))

(; Get persons who did not order anything)
(; Gets bob and sue)
(!= (get person instance *)

     (get * order (get product instance *)))

(; Set products not ordered by each person)
(; Simultaneously gets:

     john not_order bread,
     john not_order wine,
     mary not_order shampoo,
     mary not_order wine,
     bob not_order shampoo ...)

(new 'not_order 'verb)
(new 'x1 'variable)
(set x1 refersTo nothing)
(set (getElemLast (change (getSeq x1 refersTo *)
                                       (get person instance *)))
       not_order
       (!= (get product instance *)
            (get (get x1 refersTo *) order *)))

(; 2nd method)
(set (getElemLast (set x1 refersTo (get person instance *)))

       not_order
       (!= (get product instance *)
            (get (filterLast (get x1 refersTo *)) order *)))

(; Delete temporary variable and data)
(delete x1)
(delete not_order)
Received on Thu Jan 04 2007 - 23:55:12 CET

Original text of this message