Discover a score higher than another course of student information

analysis of idea:

First, the sub-query results as a table, filter data

1, these two courses are grouped according to Student ID display

2, the query result as a table top, appropriate data rescreened

select * from
(
SELECT
sno,
max(case when cno='3-105' then DEGREE else 0 end) dg105,
max(case when cno='3-245' then DEGREE else 0 end) dg245
FROM score
where CNO in ('3-105','3-245')
group by sno
) a
where a.dg105>0 and a.dg245>0 and a.dg105>a.dg245

Second, do the results table associated with the query

SELECT * FROM score a, score b
WHERE a.SNO=b.SNO 
AND a.CNO='3-105'
AND b.CNO='3-245'
AND a.DEGREE>b.DEGREE

Guess you like

Origin www.cnblogs.com/jane4321/p/12173850.html