Write an sql query to sort a table according to the amounts in a row and find the second largest amount.
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 |
CTE(common table expression)
How to create a new login name in ms sql server?
Explain error handling in ssis?
How you would rewrite the sql query to return the customerid sorted numerically?
Do you know the cursor optimization tips?
how can i store resumes in database?
How to get nth highest salary from employee table.
What is normalization and its types?
What are the different types of upgrades that can be performed in sql server?
difference between function and procedure
3 Answers Cognizant, HCL, TCS, Theorem,
What can be used instead of trigger?
How many types of the database links?
Oracle (3253)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)