santhosha santhosha - 1 year ago 72
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 Source

You could use a subquery to do this:

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