Information générale
Catégorie:
Codage, syntaxe et commandes
>>>>Can anyone tell me if the following can be done in a one line select statement. I cannot seem to get the results I require.
>>>>
>>>>I have one table with the following fields: Customer, Date, Price. I am simply trying to get the last price quoted to the customer.
>>>>
>>>>CustA, 01/01/01, 100
>>>>CustA, 01/01/97, 111
>>>>CustB, 02/02/96, 200
>>>>CustB, 02/02/02., 222
>>>>
>>>>I want my result to be:
>>>>
>>>>CustA, 01/01/97, 111
>>>>CustB, 02/02/96, 200
>>>>
>>>>If I use SELECT * FROM myTable ORDER BY Date DESC GROUP BY Customer
>>>>I get ...
>>>>CustA, 01/01/01, 100
>>>>CustB, 02/02/01, 222
>>>>
>>>>Again, I am looking for the last price quoted only.
>>>>
>>>>Any help would be greatly appreciated.
>>>>
>>>>-Isaac Roda
>>>
>>>Sorry, it's two lines:
>>>select * from table1 into cursor tmp1 order by customer,date
>>>select * from tmp1 group by customer
>>
>>Hello Ed,
>>
>>I tried the following
>>
>>sele * from price order by cust,date desc into cursor t1
>>sele * from t1 group by cust
>>
>>and still get the wrong results.
>>I am trying to get the newest date for each customer. I tried some variations of the above and no matter what the result always seems to be the oldest date, not the newest date. Any Ideas?
>
>Try the answer you got already, please.
Forgive my thick head. My silly logic was to first include the DESC clause for sorting by date, but leaving this out did the trick. Thanks again.
-Isaac
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement