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. python3.x - python连oanda的模拟交易api获取json问题第五问2. javascript - 怎么简写这段jQuery功能?3. java - Atom中文问题4. angular.js - angularjs 使用modal 选中modal中的li列表后传值5. angular.js - 请教一个关于angularjs的小问题6. angular.js - 这是什么错?谁遇到过?给点提示7. 关于Apache无法启动的程序的方式是怎么解决的8. android - webview 想打开word ppt excel pdf 大家有做过的吗9. 表单内容含有多选、单选和下拉怎么通过ajax传到数据库,(请把控制器部分和model部分也带上)10. angular.js - 用angular2-cli打包项目之后,跳转路由刷新会报404的错误
