2013-07-10 98 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