我有这个问题:
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)
由于
答案 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;