Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sql return two max values
Message
 
 
À
08/09/2003 10:57:18
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00827089
Message ID:
00827124
Vues:
21
Steve,

Try (untested)
SELECT vendor, invoice_date, invoice_amount
	FROM mytable mt
	JOIN (
		SELECT vendor, invoice_date, max(invoice_amount) AS invoice_amount
			FROM mytable mt1 ;
			WHERE invoice_date IN 
				(SELECT max(invoice_date) FROM mytabel mt2
					WHERE mt2.vendor = mt1.vendor)
GROUOP BY vendor, invoice_date
) dt1
		ON dt1.vendor = mt.vendor
			AND dt1.invoice_date = mt.invoice_date
			AND dt1.invoice_amount = mt.invoice_amount
     
>Hi:
>
>Unfortunately, this is no unique key in this table (not my design). I need to find the vendor with the lastest invoice date with the highest invoice amount.
>
>I hope this clears things up. Thanks for your help.
>
>
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform