sqlserver - mysql如何查詢多列重復(fù)的數(shù)據(jù)個(gè)數(shù)?
問題描述
只會(huì)差尋一列,求教如何查詢多列數(shù)據(jù)重復(fù)個(gè)數(shù)!
問題解答
回答1:我的意見是數(shù)據(jù)庫(kù)簡(jiǎn)單提取數(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 ...
感覺好粗鄙,等大神來(lái)。
回答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. 在應(yīng)用配置文件 app.php 中找不到’route_check_cache’配置項(xiàng)2. html按鍵開關(guān)如何提交我想需要的值到數(shù)據(jù)庫(kù)3. mysql取模分表與分表4. gvim - 誰(shuí)有vim里CSS的Indent文件, 能縮進(jìn)@media里面的5. HTML 5輸入框只能輸入漢字、字母、數(shù)字、標(biāo)點(diǎn)符號(hào)?正則如何寫?6. 跟著課件一模一樣的操作使用tp6,出現(xiàn)了錯(cuò)誤7. PHP類屬性聲明?8. objective-c - ios 怎么實(shí)現(xiàn)微信聯(lián)系列表 最好是swift9. javascript - 請(qǐng)教如何獲取百度貼吧新增的兩個(gè)加密參數(shù)10. java - 安卓接入微信登錄,onCreate不會(huì)執(zhí)行
