A few days ago to participate in an interview, interview company to do a set of questions, SQL problem is not difficult, but I was the first to write the wrong, come back, write the next. Simply record it,
1. Title:
2. Test data
SELECT * from student; INSERT into student (Name,subject,score) VALUES (' Zhang ', ' language ', "); INSERT into student (Name,subject, Score) VALUES (' Zhang ', ' math ', ' a '), insert into student (Name,subject,score) VALUES (' Zhang ', ' English '), insert into student (name, Subject,score) VALUES (' King ', ' language ', ' n '), insert into student (Name,subject,score) VALUES (' King ', ' English '), insert into student ( Name,subject,score) VALUES (' Li ', ' math '), insert into student (Name,subject,score) VALUES (' Zhao ', ' English ', 88);
Student table, altogether three fields name, subject, score (data types are varchar (), varchar (+), int), test table, relatively simple.
3. I wrote the SQL
Select M.name from (select S.name, S.score, Dense_rank () through (PARTITION by s.name ORDER by s.score ASC) as Score_rank from Student s) m where M.score_rank = 1 and M.score >=60;
If you have any objection, please correct me.
Interview questions: SQL data query