0

我有那张桌子:

论坛:

 _____________________________________________________________
|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 

它将给出与前一个查询相同的结果,但每条记录都有一个时间戳值

我希望这个值是最近的时间戳,可以这样做吗?

4

2 回答 2

0

只需使用 max() 函数。

select forum.match_static_id, 
   count(forum.match_static_id) 'comment_no',
   max(forum.timestamp)
Group By forum.match_static_id

这是可用聚合函数的列表和说明。

于 2013-07-10T11:51:40.630 回答
0

这个怎么样:

select forum.match_static_id, 
count(forum.match_static_id) 'comment_no',
max(forum.timestamp)
Group By forum.match_static_id
于 2013-07-10T11:52:33.720 回答