Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi , this my table student how to find 2 rank of this table
can you write query for this table without total how to find rank

studId studName mark1  mark2   mark3
S001	Raja	60	70        40
S002	Siva	40  	79        77
S003	Kumar	80	30        90
S004	Mani	60	70        40
-------------------------------------
Posted
Updated 31-Aug-12 20:21pm
v2

if you don't wanna insert a sum into table then.. made it in query itself..
using below query you will get 2nd rank students details without store a sum in your table..

SQL
select * from exam where (mark1+mark2+mark3) = select max(mark1+mark2+mark3) test From eaxm where (mark1+mark2+mark3)  not in (select max(mark1+mark2+mark3)  test From exam)
 
Share this answer
 
v2
HI ,,,,

Please try the below query
SQL
with cte_ex as 
(select distinct studId,studName,(mark1+mark2+mark3) as sumt,ROW_NUMBER() over (order by (select 1 ))as rowno from tmpstd)
select  A.studId,A.studName,A.sumt  from cte_ex A
join cte_ex B on A.rowno=B.rowno 
where A.rowno=2
 
Share this answer
 
v2
I am giving you max 2 highest salary example

Select max(sal)
from Emp
where sal not in (Select top 1 sal from Emp)
 
Share this answer
 
StudentID	Name	Mark1	Mark2	Mark3	Sum
S001		Raju	60	70	40	170
S002		Siva	40	79	77	196
S003		Kumar	80	30	90	200
S004		Mani	60	70	40	170



SQL
SELECT MAX(Sum1) FROM Exam WHERE sum1 NOT IN (SELECT MAX(sum1) FROM Exam)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900