Hi friends, in this article I will explain about How to Get Highest and Lowest Values in a Row using SQL SERVER.
I already explained in the previous articles about How to Display DateTime Formats in Different Languages using SQL Server, How to Calculate Age from Date Of Birth using SQL Server and How to encrypt/decrypt string in sql server
DBScript:
DBScript:
DECLARE @MARKS TABLE(ID INT PRIMARY KEY,
Name VARCHAR(15),
MATHS INT,
SCIENCE INT,
SOCIAL INT)
INSERT INTO @MARKS VALUES(1,'KISHORE',75,95,66)
INSERT INTO @MARKS VALUES(2,'ROJA',96,85,75)
INSERT INTO @MARKS VALUES(3,'KRISH',55,95,80)
INSERT INTO @MARKS VALUES(4,'ANIL',90,60,80)
SELECT M.ID,TT.MaxMarks,TT.MinMarks FROM @MARKS AS M
CROSS APPLY
(
SELECT MAX(ROW) AS MaxMarks,MIN(ROW) AS MinMarks
FROM(
SELECT MATHS UNION ALL
SELECT SCIENCE UNION ALL
SELECT SOCIAL
) AS TEMP(ROW)
) AS TT
|
The output of the above code as shown in the below figure.
No comments:
Post a Comment