sql

0 pts.
Tags:
SQL
Hi, Imagine such a table : prod_key item_key pack_key last_sale PE12343 2029 BC400 05/12/2003 LM10212 2029 BC400 04/08/2004 PE12000 1345 AD100 08/04/2005 LM34598 1345 AD100 13/07/2005 I want to get the following rows : LM10212 2029 BC400 04/08/2004 LM34598 1345 AD100 13/07/2005, which select the last sale on item_key and pack_key independently of the product_key, but I need to show the product. Can somebody help me ?
ASKED: September 30, 2005  2:16 AM
UPDATED: September 30, 2005  2:44 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

You can get the best record from this set as follows:

WITH bestRecords AS(
SELECT item_key,
pack_key,
MAX(last_sale) last_sale
FROM such_a_table
GROUP BY item_key, pack_key)
SELECT sat.*
FROM bestRecords br,
such_a_table sat
WHERE br.item_key=sat.item_key AND
br.pack_key=sat.pack_key AND
br.last_sale=sat.last_sale;

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following