Write an sql query to sort a table according to the amounts in a row and find the second largest amount.



Write an sql query to sort a table according to the amounts in a row and find the second largest amo..

Answer / Ajendra Singh

Assuming you have a table named `MyTable` with a column named `Amount`, here's an SQL query that sorts rows by Amount in descending order and returns the second largest value:n```nSELECT MAX(Amount) as LargestAmount, MIN(CASE WHEN Amount = (SELECT MAX(Amount) FROM MyTable) THEN NULL ELSE Amount END) as SecondLargestAmountnFROM MyTable;n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

CTE(common table expression)

1 Answers   Thomson Reuters,


How to create a new login name in ms sql server?

1 Answers  


Explain error handling in ssis?

1 Answers  


How you would rewrite the sql query to return the customerid sorted numerically?

1 Answers  


Do you know the cursor optimization tips?

1 Answers  


how can i store resumes in database?

3 Answers   HCL,


How to get nth highest salary from employee table.

1 Answers  


What is normalization and its types?

1 Answers  


What are the different types of upgrades that can be performed in sql server?

1 Answers  


difference between function and procedure

3 Answers   Cognizant, HCL, TCS, Theorem,


What can be used instead of trigger?

1 Answers   ADITI,


How many types of the database links?

1 Answers   MCN Solutions,


Categories