在网站上获取最新访客

时间:2011-06-08 13:09:03

标签: mysql sql

我有一个名为“流量”的表格,用于记录网站访问者。

每个页面视图都会被记录,因此每个IP地址都有多个条目。

我需要检索按IP地址分组的最新访问。我怎么能这样做?

列:id(autoinc),ipaddress(varchar),lastActivity(datetime)

2 个答案:

答案 0 :(得分:1)

select f.ipaddress , f.lastActivity 
from (
   select ipaddress , max(lastActivity) as maxdate
   from traffic group by ipaddress ) as x
   inner join traffic as f 
   on f.ipaddress = x.ipaddress and f.lastActivity= x.maxdate; 

答案 1 :(得分:-1)

Select * from traffic GROUP BY ipaddress ORDER BY lastActivity DESC