如何从MySQL的每个组中选择第二行

时间:2016-09-30 07:41:39

标签: mysql

如何从MySQL中选择每一组的第二行,如下图所示。

enter image description here

1 个答案:

答案 0 :(得分:2)

在MySQL中使用以下查询:

SELECT C.groupname,C.marks FROM querysecondval C LEFT JOIN(SELECT A.groupid,IFNULL(B.groupid,0)groupid2 FROM querysecondval LEFT JOIN(选择B.groupid FROM querysecondval B GROUP BY B.groupname order by B.groupid)B ON A.groupid = B.groupid )D ON C.groupid = D.groupid WHERE D.groupid2 = 0 GROUP BY C.groupname order by C.groupid