Get the largest amount and its id in sql

1

I have three records and I want to affect the highest amount I get with the MAX (Quantity). to make a subtraction to the greater amount. but it affects the three records that I have. I take care to bring the last amount also get its id to affect only that record?

Greetings

This is my query to get the id EntryEntryDetID = 1 to update the largest amount that in this case is 1166.66 of the EntryEntryDetID 1.

    
asked by Alvaro Montoro 02.10.2017 в 21:06
source

1 answer

0

To obtain the id of the record with the greatest number, it would be like this:

DECLARE @Id_Mayor_Cantidad int

SELECT @Id_Mayor_Cantidad = (SELECT LlavePrimaria FROM Tabla WHERE Cantidad=(SELECT MAX(Cantidad) FROM Tabla))

And you would already have the Id in the variable @Id_Mayor_Quantity

    
answered by 03.10.2017 / 04:38
source