sql - Get second highest salary from each deptno -


how second highest salary each deptno following table?

id name                        age     deptno     salary -- -------------------- ---------- ---------- ----------  1 shasank                      25         11       2025  2 raju                         27         12       2027  3 son                          33         12       2131  6 bali                         31         10       2031  4 rambo                        34         11       2345  5 don                          32         11       2132  7 dimpu                        31         12       2121  8 rahul                        28         10       2341  9 janny                        28         10       2123 

if you're using system supports sql ranking functions, dense_rank you're seeking. below sql server 2005 or later:

select     * --todo - pick columns     (         select *,dense_rank() on (partition deptno order salary desc) rnk         table     )     rnk = 2 

(sql server documentation on dense_rank)


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -