mysql overall ranking.

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

CREATE TABLE `user_data` (
  `u_id` int NOT NULL,
  `nick_name` varchar(255) NOT NULL,
  `kor` int NOT NULL,
  `eng` int NOT NULL,
  `math` int NOT NULL,
  `date` date NOT NULL

SELECT * FROM (SELECT u_id, nick_name, kor, ROW_NUMBER() OVER (ORDER BY kor DESC) AS salary_rank FROM user_data) salary_rank

As I searched the Internet, I could get a rank (rank) for each subject in this way.

How do I get the total national total score for each student?

I was doing this and that, but I kept getting angry because of the error, so I posted a question<

Please explain with the explanation.


2022-09-19 23:32

1 Answers

Looking at the table structure you uploaded, and to infer from the practice very empirically, what you want is a query that aligns the user_data table so that the kor+eng+math value is large and then SELECT.

Then I think we can just do it like this.?

-- Caution: I haven't tested it.
    u_id, nick_name, kor, eng, math,
    ROW_NUMBER() OVER (ORDER BY kor+eng+math DESC) AS `rank`
  FROM `user_data`
) user_rank;

2022-09-19 23:32

If you have any answers or tips

© 2022 pinfo. All rights reserved.