dbTalk Databases Forums  

SQL Query with grouping

comp.databases.xbase.fox comp.databases.xbase.fox


Discuss SQL Query with grouping in the comp.databases.xbase.fox forum.



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

Default SQL Query with grouping - 04-06-2004 , 01:24 PM






Hi,

Have a table with repeating customer ID with date. Need to group date
together based on customer ID.

Table now looks like this:
1 Apr 3, 2004
1 Apr 4, 2004
2 Mar 30, 2004
2 Mar 31, 2004
3 Apr 4, 2004
3 Mar 31, 2004

Query should be able to give me results like this:
1 Apr 3, 2004
Apr 4, 2004
2 Mar 30, 2004
Mar 31, 2004
3 Apr 4, 2004
Mar 31, 2004

Reply With Quote
  #2  
Old   
Rick Bean
 
Posts: n/a

Default Re: SQL Query with grouping - 04-09-2004 , 02:53 PM






Steve,
From the data you presented, it's not clear what you really want to do. If it's for a report, then you could just use a select with an order by clause - assuming you don't already have the appropriate index.

1) SELECT cust_id, dDate ;
FROM mytable ;
ORDER BY cust_id, dDate ;
INTO cursor myCursor

2) INDEX ON cust_ID+DTOS(dDATE)

Note: If you want only 3 records out with an indeterminate number of fields (max based on number of records for the customer with the most records), this will take a bit more work.

Rick

"Steve" <guddi_23 (AT) yahoo (DOT) com> wrote

Quote:
Hi,

Have a table with repeating customer ID with date. Need to group date
together based on customer ID.

Table now looks like this:
1 Apr 3, 2004
1 Apr 4, 2004
2 Mar 30, 2004
2 Mar 31, 2004
3 Apr 4, 2004
3 Mar 31, 2004

Query should be able to give me results like this:
1 Apr 3, 2004
Apr 4, 2004
2 Mar 30, 2004
Mar 31, 2004
3 Apr 4, 2004
Mar 31, 2004

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.