Mysql 按问题进行计数和分组
我有那张桌子: 论坛:Mysql 按问题进行计数和分组,mysql,count,group-by,Mysql,Count,Group By,我有那张桌子: 论坛: _____________________________________________________________ |match_static_id| comment | timpstamp | user_id | |_______________|___________|______________________|__________| | 1 | Hi | 2013-07-10 12:15:
_____________________________________________________________
|match_static_id| comment | timpstamp | user_id |
|_______________|___________|______________________|__________|
| 1 | Hi | 2013-07-10 12:15:03 | 2 |
| 1 | Hello | 2013-07-09 12:14:44 | 1 |
|_______________|___________|______________________|__________|
工作查询是:
select forum.match_static_id,
count(forum.match_static_id) 'comment_no'
Group By forum.match_static_id
但如果我想要:
select forum.match_static_id,
count(forum.match_static_id) 'comment_no',
forum.timestamp
Group By forum.match_static_id
它将给出与前一个查询相同的结果,但每个记录的值都是timestamp
我希望此值是可以完成的最新时间戳?只需使用max()函数即可
select forum.match_static_id,
count(forum.match_static_id) 'comment_no',
max(forum.timestamp)
Group By forum.match_static_id
以下是可用的列表和说明。这个怎么样:
select forum.match_static_id,
count(forum.match_static_id) 'comment_no',
max(forum.timestamp)
Group By forum.match_static_id