2013-07-10 97 views
0

我有一个表:计数和group by问题

论坛:

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

它会给出与前一个查询bu相同的结果吨与每个记录的时间戳值

我希望这个值是最近可以完成的时间戳吗?

回答

0

只需使用max()函数。

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

这里是可用的aggregate functions的列表和解释。

+0

非常感谢你能正常工作。 – Basel

0

如何:

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