Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在一张桌子上占上风?_Mysql - Fatal编程技术网

Mysql 在一张桌子上占上风?

Mysql 在一张桌子上占上风?,mysql,Mysql,我有桌子 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 ) ENGIN

我有桌子

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; 如果不存在“日志”,则创建表( `userid`int(11)不为空, `ipaddress`char(15)字符集utf8 COLLATE utf8\u bin非空, `hwid`char(32)字符集utf8 COLLATE utf8\u bin NOT NULL, `lastlogin`int(10)未签名非空 )ENGINE=MyISAM默认字符集=1;
我想做的是获取具有最不同HWID的用户ID。在添加hwid之前,我可以通过使用DISTINCT和GROUP by userid获得具有最不同IP的用户ID。

谢谢,我没有想到这一点。
SELECT  userid, COUNT(DISTINCT hwid) AS cnt
FROM    logs
GROUP BY
        userid
ORDER BY
        cnt DESC
LIMIT 10