这是 SQL 表和插入:create table esm (etud INT(11), sess INT(11), modval char(3))
INSERT INTO esm (etud,sess,modval) VALUES ( 1,1,'M1');
INSERT INTO esm (etud,sess,modval) VALUES ( 1,2,'M1');
INSERT INTO esm (etud,sess,modval) VALUES ( 2,1,'M1');
INSERT INTO esm (etud,sess,modval) VALUES ( 3,1,'M1');
INSERT INTO esm (etud,sess,modval) VALUES ( 4,1,'M1');
和查询:
SELECT esm1.* FROM esm esm1
INNER JOIN (SELECT MIN(etud) as minetud, sess, modval
FROM esm
GROUP BY sess, modval) esm2
ON esm1.sess=esm2.sess AND esm1.modval=esm2.modval
WHERE esm1.etud <> minetud;
我的结果与您期望的结果不同,但我认为它们反映了您对问题的陈述。
+------+------+--------+
| etud | sess | modval |
+------+------+--------+
| 2 | 1 | M1 |
| 3 | 1 | M1 |
| 4 | 1 | M1 |
+------+------+--------+