一个查询问题..这次应该简单点了.. 本帖最后由 stneo1990 于 2012-04-25 18:10:20 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 SELECT * FROM(SELECT `id`, `reply_id`, `name`, `content`, `time` FROM `reply` ORDER BY `time` DESC) tblGROUP BY `reply_id`ORDER BY `time` DESC 参考下贴中的多种方法http://topic.csdn.net/u/20091231/16/2f268740-391e-40f2-a15e-f243b2c925ab.html[征集]分组取最大N条记录方法征集,及散分.... 其中的一种解法如下。mysql> select * from reply;+----+----------+-------+---------+------+| id | reply_id | name | content | time |+----+----------+-------+---------+------+| 1 | 1 | test1 | test1 | 1 || 2 | 1 | test2 | test2 | 3 || 3 | 2 | test3 | test3 | 2 || 4 | 2 | test4 | test4 | 4 || 5 | 3 | test5 | test5 | 1 || 6 | 3 | test6 | test6 | 2 || 7 | 3 | test7 | test7 | 5 |+----+----------+-------+---------+------+7 rows in set (0.00 sec)mysql> select * from reply r -> where not exists (select 1 from reply where reply_id=r.reply_id and time>r.time) -> order by time desc;+----+----------+-------+---------+------+| id | reply_id | name | content | time |+----+----------+-------+---------+------+| 7 | 3 | test7 | test7 | 5 || 4 | 2 | test4 | test4 | 4 || 2 | 1 | test2 | test2 | 3 |+----+----------+-------+---------+------+3 rows in set (0.00 sec)mysql> 我想先order by time desc..再group by reply_id...group by 总是只保留第一个的吧?.. mysql 插入更新记录 请教 这里的高手帮心看看。为什么会有这么多mysql进程 我想用mysql做个小型的数据库系统 mysql插入很小的数据时那个表文件没有变化? mysql 两边数据转移怎么转? 关于mysql查询的奇怪问题~~ mysql已经指定主键了,为什么用phpMyAdmin插入的时候,主键设置为空也不报错啊? 再问mysqlimport问题,请高手指点 如何实现这样的联结查询 mysql中怎么把数据倒出来? Show databases 无法显示全部数据库 Mysql中如何是\不作为转义字符输出
(SELECT `id`, `reply_id`, `name`, `content`, `time` FROM `reply` ORDER BY `time` DESC) tbl
GROUP BY `reply_id`
ORDER BY `time` DESC
[征集]分组取最大N条记录方法征集,及散分....
mysql> select * from reply;
+----+----------+-------+---------+------+
| id | reply_id | name | content | time |
+----+----------+-------+---------+------+
| 1 | 1 | test1 | test1 | 1 |
| 2 | 1 | test2 | test2 | 3 |
| 3 | 2 | test3 | test3 | 2 |
| 4 | 2 | test4 | test4 | 4 |
| 5 | 3 | test5 | test5 | 1 |
| 6 | 3 | test6 | test6 | 2 |
| 7 | 3 | test7 | test7 | 5 |
+----+----------+-------+---------+------+
7 rows in set (0.00 sec)mysql> select * from reply r
-> where not exists (select 1 from reply where reply_id=r.reply_id and time>r.time)
-> order by time desc;
+----+----------+-------+---------+------+
| id | reply_id | name | content | time |
+----+----------+-------+---------+------+
| 7 | 3 | test7 | test7 | 5 |
| 4 | 2 | test4 | test4 | 4 |
| 2 | 1 | test2 | test2 | 3 |
+----+----------+-------+---------+------+
3 rows in set (0.00 sec)mysql>
我想先order by time desc..再group by reply_id...
group by 总是只保留第一个的吧?..