不知怎么的,一个表有垃圾数据,需要清理它并生成一个新的表。
我认为它应该用用例或一些row_number结束,尝试了几次,失败了。
数据库是mysql。
原表:
Student Registration Course
John CS
John 2018
John 2017
Peter 2019 MATH
Mary 2016 MATH
Mary 2016 CS规则是,如果我们有一个学生的重复记录,合并他们在一起,为了注册,取最多一年。如果没有像玛丽那样的列缺失。按航向asc订购,记录第一次。其结果将是:
Student Registration Course
John 2018 CS
Peter 2019 MATH
Mary 2016 CS发布于 2019-08-19 14:33:34
看起来您需要聚合:
select student
, max(registration) as registration
, min(course) as course
from original
group
by student;发布于 2019-08-19 14:33:34
SELECT Student, MAX(Registration), MAX(Course)
-- or MIN(Course) if you want the first alphabetical
FROM YourTable
GROUP BY Studenthttps://stackoverflow.com/questions/57558857
复制相似问题