dbTalk Databases Forums  

Oreder before a certain date

comp.databases.pick comp.databases.pick


Discuss Oreder before a certain date in the comp.databases.pick forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ck
 
Posts: n/a

Default Oreder before a certain date - 06-24-2011 , 12:54 PM






Being a Friday I can't seem to think. My brain has left for the
weekend, so I ask the group:

I have a file with customer orders, how would I get a list of
customers who have not placed an order in the last three years?

Reply With Quote
  #2  
Old   
Brian Speirs
 
Posts: n/a

Default Re: Oreder before a certain date - 06-24-2011 , 01:52 PM






You would need to do something like:

SELECT the orders file for orders in the last three years

The objective here is to get a select list of the customer ids who have
ordered. Then:

NSELECT the customers file.

Cheers,

Brian

On 24/06/2011 6:54 p.m., ck wrote:
Quote:
Being a Friday I can't seem to think. My brain has left for the
weekend, so I ask the group:

I have a file with customer orders, how would I get a list of
customers who have not placed an order in the last three years?

Reply With Quote
  #3  
Old   
frosty
 
Posts: n/a

Default Re: Oreder before a certain date - 06-24-2011 , 03:12 PM



Quote:
On 24/06/2011 6:54 p.m., ck wrote:
Being a Friday I can't seem to think. My brain has left for the
weekend, so I ask the group:

I have a file with customer orders, how would I get a list of
customers who have not placed an order in the last three years?
On 6/24/11 12:52 PM, Brian Speirs wrote:
Quote:
You would need to do something like:

SELECT the orders file for orders in the last three years

The objective here is to get a select list of the customer ids who have
ordered. Then:

NSELECT the customers file.
OP didn't mention which O/S, so NSELECT might not be available.
Here's a "vanilla" eqivalent, written for uniData:
CREATE-FILE TEMP.CUST 1 11
select ORDER.FILE SAVING UNIQUE CUSTOMER.ID
UPDATE TEMP.CUST [ENTER] 1 [ENTER] 1 [ENTER]
SELECT ORDER.FILE WITH ORDER.DATE GE "6/24/2008"
select ORDER.FILE SAVING UNIQUE CUSTOMER.ID
DELETE TEMP.CUST [ENTER] Y [ENTER]
SELECT TEMP.CUST

YMMV, of course, depending on your O/S, the names of the Order and
Customer file, the attribute name in the DICT of the Order file for
the Customer ID.

--
frosty

Reply With Quote
  #4  
Old   
Tony Gravagno
 
Posts: n/a

Default Re: Oreder before a certain date - 06-24-2011 , 04:26 PM



Quote:
OP didn't mention which O/S, so NSELECT might not be available.
Here's a "vanilla" eqivalent, written for uniData:
.. SAVING UNIQUE CUSTOMER.ID
UPDATE TEMP.CUST [ENTER] 1 [ENTER] 1 [ENTER]
Since when is that syntax "vanilla"?

Reply With Quote
  #5  
Old   
frosty
 
Posts: n/a

Default Re: Oreder before a certain date - 06-24-2011 , 04:53 PM



Quote:
OP didn't mention which O/S, so NSELECT might not be available.
Here's a "vanilla" eqivalent, written for uniData:
.. SAVING UNIQUE CUSTOMER.ID
UPDATE TEMP.CUST [ENTER] 1 [ENTER] 1 [ENTER]

On 6/24/11 3:26 PM, Tony Gravagno wrote:
Since when is that syntax "vanilla"?
Since I've only been writing in uniData for the last 9+ years. =`;^p

Actually, I set out to write a vanilla solution, then realized that I
didn't have a vanilla system to test it on. (And that my vanilla skillz
had evaporated over the last decade.) As Tony points out, this is a
uniData solution. But "YMMV... depending on your O/S" applies.

I suppose you could use "EDIT" instead of "UPDATE" then build a
prestore command that does "FI" on each edited record. But I
hesitate to post
=c fi`=c [ENTER] =c [ENTER]
and that nasty ESC syntax for vanilla Pick is just... nasty.

Perhaps there's an equivalent of uniData UPDATE in teh Pick?

--
frosty

Reply With Quote
  #6  
Old   
Kevin Powick
 
Posts: n/a

Default Re: Oreder before a certain date - 06-24-2011 , 05:20 PM



On 2011-06-24 17:26:41 -0400, Tony Gravagno
<tony_gravagno (AT) nospam (DOT) invalid> said:

Quote:
OP didn't mention which O/S, so NSELECT might not be available.
Here's a "vanilla" eqivalent, written for uniData:
.. SAVING UNIQUE CUSTOMER.ID
UPDATE TEMP.CUST [ENTER] 1 [ENTER] 1 [ENTER]

Since when is that syntax "vanilla"?
The very vanilla approach - Assuming goal is to get a list of customers.

- Create a file TEMP-CUSTOMERS
- Copy customers to temp-customers
- Select customer id from order file for orders GE 3yr old date
- Delete items from temp customers
- Select temp-customers (you now have your desired list).

e.g.

CREATE-FILE TEMP-CUSTOMERS 1 17

COPY CUSTOMERS *
TO: (TEMP-CUSTOMERS

SELECT ORDER-FILE CUST.ID WITH ORDER.DATE GE "24JUN08"

DELETE TEMP-CUSTOMERS

SELECT TEMP-CUSTOMERS

A cleaner, less primitive solution would be to write a simple BASIC
program to build a list and then save it.

--
Kevin Powick

Reply With Quote
  #7  
Old   
Tony Gravagno
 
Posts: n/a

Default Re: Oreder before a certain date - 06-25-2011 , 04:59 PM



Quote:
Being a Friday I can't seem to think. My brain has left for the
weekend, so I ask the group:

I have a file with customer orders, how would I get a list of
customers who have not placed an order in the last three years?
I just took a shot at this in D3, not wanting to create a temp file
that included complete records.
(Comments are in parentheses)


(Get all subscribers = customers)
:SELECT REG.SUBSCRIBER

[404] 48 items selected out of 48 items.
(Save the list of everyone)
Quote:
SL SUB1
List 'SUB1' in file 'pointer-file' saved.

(Get recent transactions = orders)
:SELECT REG.SUBSCRIPTION WITH DATE > 05/15

[404] 43 items selected out of 89 items.

(Within those items, extract the subscriber ID)
Quote:
QSELECT REG.SUBSCRIPTION (4
[404] 43 items selected out of 43 items.
(Save recently referenced subscriber/customer IDs)
Quote:
SL SUB2
List 'SUB2' in file 'pointer-file' saved.
(GL is shortcut for GET-LIST, note Unique option)
:GL SUB2 (U

pointer-file 'SUB3' size = 228

(Re-save the now shorter list, SL=SAVE-LIST)
Quote:
SL SUB2
List 'SUB2' in file 'pointer-file' saved.

(Helpful list operation)
:COMPARE-LIST SUB1 - SUB2 SUB3

(Final list is in SUB3, sort it)
:SORT-LIST SUB3

(Edit-list, now has 31 items)
:EL SUB3

With the above, and other suggestions in this thread, someone can
quickly create a cross-platform verb (or wrapper for QSelect) which
performs this relatively common data operation.

HTH

Reply With Quote
  #8  
Old   
Frank Winans
 
Posts: n/a

Default Re: Oreder before a certain date - 06-25-2011 , 10:58 PM



"Tony Gravagno" wrote
Quote:
I just took a shot at this in D3, not wanting to create a temp file
that included complete records.
(Comments are in parentheses)

(Get all subscribers = customers)
:SELECT REG.SUBSCRIBER

[404] 48 items selected out of 48 items.
(Save the list of everyone)
SL SUB1

List 'SUB1' in file 'pointer-file' saved.

(Get recent transactions = orders)
:SELECT REG.SUBSCRIPTION WITH DATE > 05/15

[404] 43 items selected out of 89 items.

(Within those items, extract the subscriber ID)
QSELECT REG.SUBSCRIPTION (4

[404] 43 items selected out of 43 items.
(Save recently referenced subscriber/customer IDs)
SL SUB2

List 'SUB2' in file 'pointer-file' saved.
(GL is shortcut for GET-LIST, note Unique option)
:GL SUB2 (U

pointer-file 'SUB3' size = 228

(Re-save the now shorter list, SL=SAVE-LIST)
SL SUB2

List 'SUB2' in file 'pointer-file' saved.

(Helpful list operation)
:COMPARE-LIST SUB1 - SUB2 SUB3

(Final list is in SUB3, sort it)
:SORT-LIST SUB3

(Edit-list, now has 31 items)
:EL SUB3

With the above, and other suggestions in this thread, someone can
quickly create a cross-platform verb (or wrapper for QSelect) which
performs this relatively common data operation.

I dunno if non-D3 flavors have REFORMAT, or if is moot point
on account of them already having the features you used above
{ QSELECT verb and (U option of GET-LIST }
but you could instead just write items in a TMP file of the qualifying
order dates as mvalues on a1, with item ids in TMP being customer id;

CLEAR-FILE TMP
SELECT ORDERS WITH DATE > "01/01/2008"
REFORMAT ORDERS CUST.ID DATE ID-SUPP
file name : ? TMP

LIST TMP A1
TMP A1
TOM 15800
14904
15530
DICK 14841

customers tom and dick were found in ORDERS in the DATE range requested.
You might want to also preserve associated ORDERS item ids as TMP A2 ;
REFORMAT ORDERS CUST.ID DATE A0 ID-SUPP
file name :? TMP

Reply With Quote
  #9  
Old   
Ed Clark
 
Posts: n/a

Default Re: Oreder before a certain date - 06-25-2011 , 11:56 PM



If you are working on an older system that doesn't do NSELECT then you
probably should have written your own by now Of course I'm
reminded of 1984 and newspeak--if you don't have a word for something,
then you may never have thought about the idea the word represents)

I guess you aren't lucky enough to have a LAST.ORDER.DATE field in the
customer file?

This is easier on some platforms than others. On universe, unidata,
cache, and I think jbase:

SELECT ORDER-FILE WITH EVERY ORDER.DATE < "06/25/2008" SAVING UNIQUE
CUSTOMER

On unidata there are some special functions that you can only use in
itypes: ADD_MONTHS() and MONTHS_BETWEEN() that would obviate hard-
coding the date if you do this often. For non-unidata, some f-
correlative gymnastics might be fun. (sorry unidata users--no f-
correlative gymnastics for you)

The above query only gets you a list of customers who have ever
actually ordered. To get the ones who haven't, hopefully you can:

SELECT CUSTOMER-FILE WITH NO ORDER.POINTERS

or

SELECT CUSTOMER-FILE
NSELECT ORDER-FILE

(if the order-file is keyed by customer)

and then merge the 2 lists with MERGE.LIST. If you are on a system
without MERGE.LIST, then maybe you should have written your own by now
too

D3 doesn't have the SAVING keyword. Again, you must have some utility
that takes a list and removes duplicates.

Reply With Quote
  #10  
Old   
frosty
 
Posts: n/a

Default Re: Oreder before a certain date - 06-26-2011 , 11:18 AM



On 6/25/11 10:56 PM, Ed Clark wrote:
Quote:
..The above query only gets you a list of customers who have ever
actually ordered. To get the ones who haven't...
"A flute without holes is not a flute."

And a Customer without Orders is not a Customer.

IMO, of course; YMMV.

--
frosty

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.