MySql查询问题上次在数据库中找到的记录

时间:2011-09-05 17:25:27

标签: mysql sql

我有这个问题:

  SELECT device, COUNT(*) 
    FROM database.table 
GROUP BY device 
  HAVING count(*) > 1 
ORDER BY device;

我需要做的是添加一个列,显示设备上次连接到数据库的时间。

该表的结构如下:

ID, device(string),
data1(int),data2(int), 
time(timestamp), 
data3(int),
data4(int)

由于

1 个答案:

答案 0 :(得分:2)

  select device, count(*) as cnt, max(time) <-- same as latest time
    from database.table 
group by device
  having cnt>1
order by device;