Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Ranking
--You create a table that has the StudentCode, SubjectCode, and Marks columns to record mid-year marks for students. --The table has marks obtained by 50 students for various subjects. --You need to ensure that the top half of the students arranged by their average marks must be given a rank of 1 --and the remaining students must be given a rank of 2. Which Transact-SQL query should you use? create table student(StudentCode int, SubjectCode int, Marks int) insert into student values (1,1,10),(1,2,20),(1,3,30) ,(2,1,30),(2,2,40),(2,3,50) ,(3,1,40),(3,2,50),(3,3,50) ,(4,1,40),(4,2,50),(4,3,50) go select StudentCode,dense_rank() over(order by avg(marks) desc) as rank from student group by studentcode SELECT StudentCode as Code, DENSE_RANK() OVER (ORDER BY AVG (Marks) DESC) AS Value FROM student GROUP BY StudentCode SELECT StudentCode as Code, NTILE (2) OVER (ORDER BY AVG (Marks) DESC) AS Value FROM student GROUP BY StudentCode -- get subjectcode,studentcode, marks of those who have maximum marks in each subject select StudentCode , SubjectCode , Marks from( select StudentCode , SubjectCode , Marks,rank() over (partition by subjectcode order by marks desc ) as rank from student) tmp where tmp.rank=1
run
|
edit
|
history
|
help
0
customers
Find gaps in timesheet data between certain hours
show open connections
Try_Parse (Type Casting )
NOT NULL field from SELECT INTO
bc160401882
Hack_this
FETCH THE WEEKDAYS DATA
Select empID whose salary is greater than their managers
bc160401693