gpt4 book ai didi

mysql - 按两列排序

转载 作者:行者123 更新时间:2023-11-29 02:30:53 27 4
gpt4 key购买 nike

我有一个包含以下列的站点访问的表格:

timestamp
host
url

我希望看到最近几次(比如 200 次)访问,但同时将同一主机的访问分组在一起(以查看他/她访问的页面顺序)。

如果我这样做:

... SORT BY timestamp DESC, host

如果多个访问者同时在线,我会搞混主机

如果我这样做:

... SORT BY host, timestamp DESC

我没有得到最新的访问(只有每个主机的最新访问)

我想看看例如

9:01 | a.com | /index
9:05 | a.com | /interesting
9:07 | a.com | /contact
9:02 | b.com | /index
9:03 | b.com | /product-a
9:08 | b.com | /thanks-for-buying

这在 Mysql 中是否可行,还是我应该在 php 中进一步处理结果?

最佳答案

试试这个:

Select *, MAX(timestamp_col) as lastVisit from site_table

GROUP BY HOSTS order by lastVisit desc

关于mysql - 按两列排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13394480/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com