Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
Crea, inserta y confirma tabla
MSQL in 10 mn ~ Lesson 9 Performing Mathematical Calculations - orderitems ~ expanded_price
Adding, subtracting, rounding and calculating differences
Branch
2021-03-09_LeetCodeSQL
Find the database which have specify table name
Trabalho.Agrecação
pivot example
ms sql where ,like
exp 8 XIV
Please log in to post a comment.