1. 需求:分组后得到id =3 和id =6 的行数
2.解决(sql)
方法一:
-- 将符合条件的id 放在where条件后 SELECT id, A, B FROM test AS a WHERE id IN ( SELECT max( b.id ) AS id FROM test AS b GROUP BY b.A )
结果:
方法二
-- 将符合条件的id 作为子查询 连接自己 SELECT a.id, a.A, a.B FROM test AS a INNER JOIN ( SELECT max( b.id ) AS id FROM test AS b GROUP BY b.A ) c ON a.id = c.id
结果: