- 论坛徽章:
- 0
|
mysql> select * from t1;
+------+------+------+------+
| id | a | b | c |
+------+------+------+------+
| 1 | 1 | 3 | 3 |
| 1 | 1 | 1 | 1 |
| 1 | 2 | 2 | 2 |
| 1 | 2 | 4 | 4 |
| 2 | 1 | 1 | 1 |
| 2 | 1 | 3 | 3 |
| 2 | 2 | 2 | 2 |
| 2 | 2 | 4 | 4 |
+------+------+------+------+
8 rows in set (0.00 sec)
mysql> select x.num,t1.* from t1 left join (select t1.id,t1.a,min(t1.b)b,t2.num from t1 left join (select id,a,count(b) num from t1 group by id,a)t2 on t1.id=t2.id group by t1.id,t1.a)x on t1.id=x.id where t1.a=x.a and t1.b=x.b;
+------+------+------+------+------+
| num | id | a | b | c |
+------+------+------+------+------+
| 2 | 1 | 1 | 1 | 1 |
| 2 | 1 | 2 | 2 | 2 |
| 2 | 2 | 1 | 1 | 1 |
| 2 | 2 | 2 | 2 | 2 |
+------+------+------+------+------+
4 rows in set (0.18 sec)
mysql>
这个可以了罢,我假设id是关键字了 |
|