我有来自 TableA 的以下一组数据
S.No StudentID Marks Description SubjectID
1 1 50 Science 1
2 1 30 Mathematics 2
3 2 25 Science 1
4 2 25 Mathematics 2
我想运行一个查询并比较科学和数学的分数,并只找出分数高于数学的学生。而且我不应该看到在两个科目中得分相同的学生。
输出:
S.No StudentID Marks Description SubjectID
1 1 50 Science 1
2 1 30 Mathematics 2
有人可以帮我做一个示例查询吗?提前致谢。
最佳答案
这是可以做到的,但需要很长的时间,但我相信会有另一个好的解决方案
select a.*
from demo a
join(
select t.StudentID
from demo t
join demo t1 on t.StudentID = t1.StudentID
and t.Description = 'Science'
and t1.Description = 'Mathematics'
and t.Marks > t1.Marks) b using(StudentID);
关于mysql - 在行级别比较标记字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46350298/