数据库结构
[code lang=“sql”]
mysql> describe users;
+———-+———-+——+—–+———+——-+
| Field | Type | Null | Key | Default | Extra |
+———-+———-+——+—–+———+——-+
| username | char(30) | NO | MUL | NULL | |
| password | char(30) | NO | MUL | NULL | |
| email | char(30) | NO | MUL | NULL | |
+———-+———-+——+—–+———+——-+
[/code]
统计相同password个数并降序:
[code lang=“sql”]SELECT password,count(*) as num FROM users
group by password order by num DESC;[/code]
统计相同password个数并降序,把前100项导出为excel
[code lang=“sql”]SELECT password,count(*) as num into outfile ‘top100.xls’ FROM users
group by password order by num DESC limit 0,100;[/code]
附: mssql导出数据为excel [code lang=“sql”]EXEC master..xp_cmdshell ‘bcp tt.dbo.user out D:data.xls -c -q -S “localhost” -U “sa” -P “123456”’[/code] mssql删除文件 [code lang=“sql”]EXEC master..xp_cmdshell ‘del D:data.xls’[/code]