56,678
社区成员
发帖
与我相关
我的任务
分享
mysql> SELECT * FROM TTQG;
+------+------+
| pid | did |
+------+------+
| 1 | 1 |
| 2 | 1 |
| 3 | 1 |
| 4 | 1 |
| 5 | 2 |
| 6 | 2 |
| 7 | 2 |
| 8 | 2 |
+------+------+
8 rows in set (0.00 sec)
mysql> SELECT * from ttqg a where 2>=(select count(*) from ttqg where a.did=did
and a.pid<=pid)
-> order by did,pid desc;
+------+------+
| pid | did |
+------+------+
| 4 | 1 |
| 3 | 1 |
| 8 | 2 |
| 7 | 2 |
+------+------+
4 rows in set (0.00 sec)
mysql>