sqlserver - mysql如何查詢多列重復的數據個數?
問題描述
只會差尋一列,求教如何查詢多列數據重復個數!
問題解答
回答1:我的意見是數據庫簡單提取數據后,有業務端處理,寫各種復雜的select查詢影響效率
回答2:select distinct q1,t1.count1,tt.q2,tt.count2 ... from tleft join (select q1,count(1) count1 from t group by q1) t1 on t1.q1 = t.q1full join ( select distinct q2,t2.count2 from t left join (select q2,count(1) count1 from t group by q2) t2 on t2.q1 = t.q1) tt on tt.q2 = t.q1 ...
感覺好粗鄙,等大神來。
回答3:select a.*,b.q2,b.q2Count,c.q3,c.q3Count from (SELECT (@n1:=@n1+1) as id,q1,count(*) AS q1Count FROM t1 GROUP BY q1) a, (SELECT (@n2:=@n2+1) as id,q2,count(*) AS q2Count FROM t1 GROUP BY q2) b, (SELECT (@n3:=@n3+1) as id,q3,count(*) AS q3Count FROM t1 GROUP BY q3) c,(select @n1:=0,@n2:=0,@n3:=0) iwhere a.id=b.id and c.id=a.id
2 D 1 B 2 D 21 B 3 C 2 E 1
相關文章:
1. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””2. Mysql如何按照日期對比數據,求SQL語句3. 為什么我輸入了refresh不會跳轉?請教大神支招!4. 我安裝了xampp集成環境,再安裝php工具箱提示80端口被占用5. java類型強轉為泛型V,竟然沒有報錯?6. phpStudy2017輕巧版mysql無法啟動7. mysql - 如何高效的查詢需要合并大數據表的操作8. javascript - 學習網頁開發,關于head區域一段腳本的疑惑9. javascript - 移動端一個小效果10. 為什么我寫的PHP不行
