sqlserver - mysql如何查詢多列重復(fù)的數(shù)據(jù)個數(shù)?
問題描述
只會差尋一列,求教如何查詢多列數(shù)據(jù)重復(fù)個數(shù)!
問題解答
回答1:我的意見是數(shù)據(jù)庫簡單提取數(shù)據(jù)后,有業(yè)務(wù)端處理,寫各種復(fù)雜的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
相關(guān)文章:
1. docker-compose中volumes的問題2. mysql 一個sql 返回多個總數(shù)3. CSS3 畫如下圖形4. 在mac下出現(xiàn)了兩個docker環(huán)境5. 如何用筆記本上的apache做微信開發(fā)的服務(wù)器6. android - rxjava merge 返回Object對象數(shù)據(jù)如何緩存7. javascript - 螞蟻金服里的react Modal方法,是怎么把元素插入到頁面最后的8. python - Scrapy存在內(nèi)存泄漏的問題。9. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個是怎么回事????10. angular.js - ionic2 瀏覽器跨域問題
