Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,705 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
In the table below, how do I group by Unit and then get the highest value from Quantity of that group? I have put 21 in row 4 under HighestValue column since its the highest value among all records in Unit
Check the queries that produce results in different forms:
select *, max(Quantity) over (partition by Unit) as HighestValue
from MyTable
select Unit, max(Quantity) as HighestValue
from MyTable
group by Unit