开发者

Sort by Log_time but into group section?

How do I sort by Log_time (DESC) but into GroupID section?

Example Data:

Field Names:
LogID
GroupID
Log_Output
Log_time


1  | xdsd | Text 1 | 2011-08-08 11:11:00
2  | x42e | Text 2 | 2011-08-08 11:12:00
3  | xdsd | Text 3 | 2011-08-08 11:13:00
4  | x42e | Text 4 | 2011-08-08 11:16:00
5  | x42e | Text 5 | 2011-08-08 11:17:00
6  | xdsd | Text 6 | 2011-08-08 11:20:00

I want it to order开发者_JAVA技巧 Like this:

6  | xdsd | Text 6 | 2011-08-08 11:20:00
3  | xdsd | Text 3 | 2011-08-08 11:13:00
1  | xdsd | Text 1 | 2011-08-08 11:11:00
5  | x42e | Text 5 | 2011-08-08 11:17:00
4  | x42e | Text 4 | 2011-08-08 11:16:00
2  | x42e | Text 2 | 2011-08-08 11:12:00


Assuming you mean that you want to sort by GroupID first, and then Log_Time for each GroupId, then this should do it:

select LogID, GroupID, Log_Output, Log_time
from table
order by GroupID, Log_time desc


Use this query:

SELECT  LogID, GroupID, Log_Output, Log_time
  FROM mytable
    ORDER BY GroupID, Log_time DESC


Use MySQL Query select a, b, c from table_name order by c desc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜