Monday, January 15, 2018

How To Find Max And Min In Mssql

Hello Friend Today In This Blog I Will Show You How To Max And Min Data In Mssql.The MIN() function returns the smallest value of the selected column.The MAX() function returns the largest value of the selected column.Max returns the maximum value of the column. It does this using the collating sequence so it can work on character and datetime columns in addition to numeric ones.Min is the inverse. It returns the smallest value of the column and also works with several different data types.The MIN and MAX functions find the minimum or maximum value in a record set. For instance, you might want to find the maximum or highest order total that's you've had while in business. You might also want to know the minimum or lowest order total value. With these business requirements, you use the MIN and MAX functions.MIN () gives the smallest figure in the given column. MAX () gives the largest figure in the given column.The max() aggregate function returns the maximum value of all values in the group. The maximum value is the value that would be returned last in an ORDER BY on the same column. Aggregate max() returns NULL if and only if there are no non-NULL values in the group.The min() aggregate function returns the minimum non-NULL value of all values in the group. The minimum value is the first non-NULL value that would appear in an ORDER BY of the column. Aggregate min() returns NULL if and only if there are no non-NULL values in the group.The MIN function returns the smallest value in the specified table field.Just as the name suggests, the MAX function is the opposite of the MIN function. It returns the largest value from the specified table field.MIN and MAX are SQL aggregation functions that return the lowest and highest values in a particular column.


MIN() Syntax

SELECT MIN(column_name)
FROM table_name
WHERE condition;

MAX() Syntax

SELECT MAX(column_name)
FROM table_name

WHERE condition;


Here Is An Example Related To Topic

Step 1 :Create database


Create database Employee



Step 2:Create table

Here In This step We Will Create table.

Here In This Step We Required Four Column With Name eids ,ename ,edept and esalary using Parameter bigint,varchar and float.

create table emp
(
eids bigint,
ename varchar(50),
edept varchar(50),
esalary float
);


Step 3 :Create Insert Trigger Functionality

Here In This Step We Will Insert Data Using Insert Command.
Data Will Be Added Manually Using Insert Command.



Insert Into emp values(1,'VIRAJ','IT',15000.00)
Insert Into emp values(2,'RAJ','MARKETING',10000.00)
Insert Into emp values(3,'ANIL','SALES',12000.00)
Insert Into emp values(4,'SUNIL','IT',9000.00)
Insert Into emp values(5,'SHERYAS','SALES',11000.00)

select *from emp




Step 4 :Create Max() Functionality

Here In This Step We Will Find Max Salary From  Data Using Max() Function.
Data Will Be Added Manually Using Max() Function.
Here We Will Find Max Salary Between Five Inserted Data from The Table.
Max Value Will Be Fine Using Max() Functionality Operator.


select MAX(esalary) AS MaxSalary from emp




Step 5 :Create Min() Functionality

Here In This Step We Will Find Mix Salary From  Data Using Min() Function.
Data Will Be Added Manually Using Min() Function.
Here We Will Find Min Salary Between Five Inserted Data from The Table.
Min Value Will Be Fine Using Min() Functionality Operator.


select MIN(esalary) AS MinSalary from emp



HERE IS THE VIDEO RELATED TO THE TOPIC


No comments:

Post a Comment