santhosha santhosha - 16 days ago 5
SQL Question

Designating Maximum record in table using SQL

Could anyone help me to achieve this using SQL. I am a very basic user in SQL and tried doing it with GROUP BY in combination with HAVING Clause but it was filtering the records which i dot want to.

All i a want to acieve here is the Relative month column. Wherever there is maximum MonthNUmber the correpsponding column should be designated as "Current Month"

enter image description here

Answer

You could use a subquery to do this:

SELECT ID,
       EmpName,
       MonthNumber,
       CASE WHEN MonthNumber = (SELECT MAX(MonthNumber) FROM yourTable)
            THEN 'Current' ELSE NULL END AS RelativeMonth
FROM yourTable