2011-09-05 39 views
0

發現我有這個疑問:MySQL查詢問題,最後一次記錄在數據庫

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) 

感謝

回答

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

這一工程十分感謝! – pointhigh