{"id":1870,"date":"2020-03-13T18:20:58","date_gmt":"2020-03-13T10:20:58","guid":{"rendered":"http:\/\/www.ouvps.com\/?p=1870"},"modified":"2020-03-13T18:31:46","modified_gmt":"2020-03-13T10:31:46","slug":"%e8%bd%acmysql%e5%88%a0%e9%99%a4%e9%87%8d%e5%a4%8d%e6%95%b0%e6%8d%ae-%e5%8e%bb%e9%87%8d%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/eepu.top\/?p=1870","title":{"rendered":"[\u8f6c]MySQL\u5220\u9664\u91cd\u590d\u6570\u636e, \u53bb\u91cd\u5206\u6790"},"content":{"rendered":"<p>\u67e5\u627e\u6240\u6709\u91cd\u590d\u6807\u9898\u7684\u8bb0\u5f55\uff1a<\/p>\n<blockquote>\n<pre>SELECT * FROM t_info a WHERE ((SELECT COUNT(*) FROM t_info WHERE Title = a.Title) &gt; 1) ORDER BY Title DESC<\/pre>\n<p>\u4e00\u3001\u67e5\u627e\u91cd\u590d\u8bb0\u5f55<\/p><\/blockquote>\n<p>1\u3001\u67e5\u627e\u5168\u90e8\u91cd\u590d\u8bb0\u5f55<\/p>\n<pre>Select * From \u8868 Where \u91cd\u590d\u5b57\u6bb5 In (Select \u91cd\u590d\u5b57\u6bb5 From \u8868 Group By \u91cd\u590d\u5b57\u6bb5 Having Count(*)&gt;1)<\/pre>\n<p>2\u3001\u8fc7\u6ee4\u91cd\u590d\u8bb0\u5f55(\u53ea\u663e\u793a\u4e00\u6761)<\/p>\n<pre>Select * From HZT Where ID In (Select Max(ID) From HZT Group By Title)<\/pre>\n<p>\u6ce8\uff1a\u6b64\u5904\u663e\u793aID\u6700\u5927\u4e00\u6761\u8bb0\u5f55 \u4e8c\u3001\u5220\u9664\u91cd\u590d\u8bb0\u5f55 1\u3001\u5220\u9664\u5168\u90e8\u91cd\u590d\u8bb0\u5f55\uff08\u614e\u7528\uff09<\/p>\n<pre>Delete \u8868 Where \u91cd\u590d\u5b57\u6bb5 In (Select \u91cd\u590d\u5b57\u6bb5 From \u8868 Group By \u91cd\u590d\u5b57\u6bb5 Having Count(*)&gt;1)<\/pre>\n<p>2\u3001\u4fdd\u7559\u4e00\u6761\uff08\u8fd9\u4e2a\u5e94\u8be5\u662f\u5927\u591a\u6570\u4eba\u6240\u9700\u8981\u7684 ^_^\uff09<\/p>\n<pre>Delete HZT Where ID Not In (Select Max(ID) From HZT Group By Title)<\/pre>\n<p>\u6ce8\uff1a\u6b64\u5904\u4fdd\u7559ID\u6700\u5927\u4e00\u6761\u8bb0\u5f55 \u4e09\u3001\u4e3e\u4f8b 1\u3001\u67e5\u627e\u8868\u4e2d\u591a\u4f59\u7684\u91cd\u590d\u8bb0\u5f55\uff0c\u91cd\u590d\u8bb0\u5f55\u662f\u6839\u636e\u5355\u4e2a\u5b57\u6bb5\uff08peopleId\uff09\u6765\u5224\u65ad<\/p>\n<pre>select * from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) &gt; 1)<\/pre>\n<p>2\u3001\u5220\u9664\u8868\u4e2d\u591a\u4f59\u7684\u91cd\u590d\u8bb0\u5f55\uff0c\u91cd\u590d\u8bb0\u5f55\u662f\u6839\u636e\u5355\u4e2a\u5b57\u6bb5\uff08peopleId\uff09\u6765\u5224\u65ad\uff0c\u53ea\u7559\u6709rowid\u6700\u5c0f\u7684\u8bb0\u5f55<\/p>\n<pre>delete from people where peopleId in (select peopleId from people group by peopleId having count(peopleId) &gt; 1) and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )&gt;1)<\/pre>\n<p><span style=\"color: #ff0000;\">\u5b9e\u9645\u6d4b\u8bd5, \u8fd9\u91cc\u4f1a\u62a5\u9519, \u9700\u8981\u7ed9 in \u548c not in \u7684select\u7ed3\u679c\u8d77\u4e2a\u522b\u540d, \u4e0b\u9762\u662f\u6211\u5b9e\u9645\u6d4b\u8bd5\u53ef\u884c\u7684sql\u8bed\u53e5, \u5728t_users\u8868\u4e2d\u7ed9wx_openid\u5b57\u6bb5\u53bb\u91cd, \u4fdd\u7559id\u6700\u5c0f\u7684\u4e00\u6761\u8bb0\u5f55:<\/span><\/p>\n<pre>delete from t_users where wx_openid in (SELECT wx_openid FROM ((select wx_openid from t_users group by wx_openid having count(wx_openid) &gt; 1)) tmp) and id not in ( SELECT id FROM (select min(id) as id from t_users group by wx_openid having count(wx_openid )&gt;1) tmp2)\n<\/pre>\n<p>3\u3001\u67e5\u627e\u8868\u4e2d\u591a\u4f59\u7684\u91cd\u590d\u8bb0\u5f55\uff08\u591a\u4e2a\u5b57\u6bb5\uff09<\/p>\n<pre> select * from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) &gt; 1)<\/pre>\n<p><em> 4\u3001\u5220\u9664\u8868\u4e2d\u591a\u4f59\u7684\u91cd\u590d\u8bb0\u5f55\uff08\u591a\u4e2a\u5b57\u6bb5\uff09\uff0c\u53ea\u7559\u6709rowid\u6700\u5c0f\u7684\u8bb0\u5f55<\/em><\/p>\n<pre> delete from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) &gt; 1) and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)&gt;1)<\/pre>\n<p>5\u3001\u67e5\u627e\u8868\u4e2d\u591a\u4f59\u7684\u91cd\u590d\u8bb0\u5f55\uff08\u591a\u4e2a\u5b57\u6bb5\uff09\uff0c\u4e0d\u5305\u542browid\u6700\u5c0f\u7684\u8bb0\u5f55<\/p>\n<pre> select * from vitae a where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) &gt; 1) and rowid not in (select min(rowid) from vitae group by peopleId,seq having count()&gt;1)<\/pre>\n<p>\u56db\u3001\u8865\u5145 \u6709\u4e24\u4e2a\u4ee5\u4e0a\u7684\u91cd\u590d\u8bb0\u5f55\uff0c\u4e00\u662f\u5b8c\u5168\u91cd\u590d\u7684\u8bb0\u5f55\uff0c\u4e5f\u5373\u6240\u6709\u5b57\u6bb5\u5747\u91cd\u590d\u7684\u8bb0\u5f55\uff0c\u4e8c\u662f\u90e8\u5206\u5173\u952e\u5b57\u6bb5\u91cd\u590d\u7684\u8bb0\u5f55\uff0c\u6bd4\u5982Name\u5b57\u6bb5\u91cd\u590d\uff0c\u800c\u5176\u4ed6\u5b57\u6bb5\u4e0d\u4e00\u5b9a\u91cd\u590d\u6216\u90fd\u91cd\u590d\u53ef\u4ee5\u5ffd\u7565\u3002 1\u3001\u5bf9\u4e8e\u7b2c\u4e00\u79cd\u91cd\u590d\uff0c\u6bd4\u8f83\u5bb9\u6613\u89e3\u51b3\uff0c\u4f7f\u7528<\/p>\n<pre>select distinct * from tableName<\/pre>\n<p>\u5c31\u53ef\u4ee5\u5f97\u5230\u65e0\u91cd\u590d\u8bb0\u5f55\u7684\u7ed3\u679c\u96c6\u3002 \u5982\u679c\u8be5\u8868\u9700\u8981\u5220\u9664\u91cd\u590d\u7684\u8bb0\u5f55\uff08\u91cd\u590d\u8bb0\u5f55\u4fdd\u75591\u6761\uff09\uff0c\u53ef\u4ee5\u6309\u4ee5\u4e0b\u65b9\u6cd5\u5220\u9664<\/p>\n<pre>select distinct * into #Tmp from tableName\ndrop table tableName\nselect * into tableName from #Tmp\ndrop table #Tmp<\/pre>\n<p>\u53d1\u751f\u8fd9\u79cd\u91cd\u590d\u7684\u539f\u56e0\u662f\u8868\u8bbe\u8ba1\u4e0d\u5468\u4ea7\u751f\u7684\uff0c\u589e\u52a0\u552f\u4e00\u7d22\u5f15\u5217\u5373\u53ef\u89e3\u51b3\u3002 2\u3001\u8fd9\u7c7b\u91cd\u590d\u95ee\u9898\u901a\u5e38\u8981\u6c42\u4fdd\u7559\u91cd\u590d\u8bb0\u5f55\u4e2d\u7684\u7b2c\u4e00\u6761\u8bb0\u5f55\uff0c\u64cd\u4f5c\u65b9\u6cd5\u5982\u4e0b \u5047\u8bbe\u6709\u91cd\u590d\u7684\u5b57\u6bb5\u4e3aName,Address\uff0c\u8981\u6c42\u5f97\u5230\u8fd9\u4e24\u4e2a\u5b57\u6bb5\u552f\u4e00\u7684\u7ed3\u679c\u96c6<\/p>\n<pre>select identity(int,1,1) as autoID, * into #Tmp from tableName\nselect min(autoID) as autoID into #Tmp2 from #Tmp group by Name,autoID\nselect * from #Tmp where autoID in(select autoID from #tmp2)<\/pre>\n<p>\u539f\u6587\u94fe\u63a5\uff1ahttps:\/\/blog.csdn.net\/l1028386804\/article\/details\/51733585<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u67e5\u627e\u6240\u6709\u91cd\u590d\u6807\u9898\u7684\u8bb0\u5f55\uff1a SELECT * FROM t_info a WHERE ((SELECT COUN [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[75],"tags":[],"_links":{"self":[{"href":"https:\/\/eepu.top\/index.php?rest_route=\/wp\/v2\/posts\/1870"}],"collection":[{"href":"https:\/\/eepu.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eepu.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eepu.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eepu.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1870"}],"version-history":[{"count":9,"href":"https:\/\/eepu.top\/index.php?rest_route=\/wp\/v2\/posts\/1870\/revisions"}],"predecessor-version":[{"id":1880,"href":"https:\/\/eepu.top\/index.php?rest_route=\/wp\/v2\/posts\/1870\/revisions\/1880"}],"wp:attachment":[{"href":"https:\/\/eepu.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eepu.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eepu.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}