Min and Max Aggregate Functions in TSQL

Min and Max Aggregate Functions in TSQL
Download PDF

Here is a sample query using the MIN and MAX functions in T-SQL:

SELECT MIN(Price) AS MinPrice, MAX(Price) AS MaxPrice

FROM Products;

This query selects the minimum and maximum values for the Price column from the Products table. The results of the query will be a single row containing the minimum and maximum values for the Price column.

Here is how the query works:

  1. The SELECT clause specifies the columns that will be included in the query results. In this case, we are using the MIN and MAX functions to calculate the minimum and maximum values for the Price column.
  2. The FROM clause specifies the table that will be used in the query. In this case, we are selecting from the Products table.
  3. The MIN and MAX functions are applied to the Price column to calculate the minimum and maximum values, respectively.
  4. The results of the query will be a single row containing the minimum and maximum values for the Price column. The AS keyword is used to specify an alias for each column in the query results, which makes it easier to refer to the columns in later parts of the query or in other queries.

Want to learn more about aggregate functions in SQL Server?

https://stevestedman.com/aggregation

 

More from Stedman Solutions:

SteveStedman5
Steve and the team at Stedman Solutions are here for all your SQL Server needs.
Contact us today for your free 30 minute consultation..
We are ready to help!

Leave a Reply

Your email address will not be published. Required fields are marked *

*