Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can this be done in one SQL Select?
Message
 
 
To
08/02/2005 18:34:29
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00984864
Message ID:
00984979
Views:
22
>>I need help in selecting records from the following table (simplified):
>>
>>CUST_ID
>>ORD_DATE
>>ORD_TIME
>>
>>For a given date (ORD_DATE), I need to select one order record per customer (CUST_ID) based on the time of order (ORD_TIME). For example, the Order Time should be the latest of the day.
>>
>>I would appreciate any suggestions.
>>
>>Thank you.
>
>Every time I've tried something like this in one statement I wind up with a sluggish pig of a query. Breaking it into two steps seems to work much better for me
>
>
>SELECT cust_id,ord_date,MAX(ord_time) FROM myTable;
> GROUP BY cust_id,ord_date;
> INTO CURSOR tmpCur
>
>SELECT myTable.* FROM myTable,tmpCur ;
> WHERE myTable.cust_id = tmpCur.cust_id;
>   AND myTable.ord_date = tmpCur.ord_date;
>   AND myTable.ord_time = tmpCur.ord_time
>
Thank you so much for your suggestion.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform