我有桌子
CREATE TABLE IF NOT EXISTS `logs` ( `userid` int(11) NOT NULL, `ipaddress` char(15) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `hwid` char(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `lastlogin` int(10) unsigned NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
我想要做的是获取具有最多不同hwids的用户标识。在我添加hwid之前,我可以使用DISTINCT和GROUP BY userid来获取具有最不同ips的用户ID。
答案 0 :(得分:2)
SELECT userid, COUNT(DISTINCT hwid) AS cnt
FROM logs
GROUP BY
userid
ORDER BY
cnt DESC
LIMIT 10