表结构呢
id uid title content create_time
select * from table1 order by create_time limit 10
这样是取出最新的10条评论,但这10条评论中有可能是同一个人发的
我要的效果是评论历史记录中最多的10个人产生的这10条数据。我知道可以通过子查询的group by,但我想知道还有其他办法只通过一条sql语句完成查询的。
@dcb3688: 除了group by,没有更好的方法了
select * from table1 where createtime in (select max(createtime) from table1 where uid in (select top 10 uid from table1 group by uid order by content desc))
SELECT * FROM ( SELECT * FROM comment ORDER BY create_time DESC ) AS t GROUP BY t.uid