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. python如何不改动文件的情况下修改文件的 修改日期2. angular.js - 不适用其他构建工具,怎么搭建angular1项目3. angular.js - Angular路由和express路由的组合使用问题4. python - django 里自定义的 login 方法,如何使用 login_required()5. java8中,逻辑与 & 符号用在接口类上代表什么意思6. mysql优化 - mysql count(id)查询速度如何优化?7. mysql主从 - 请教下mysql 主动-被动模式的双主配置 和 主从配置在应用上有什么区别?8. 主从备份 - 跪求mysql 高可用主从方案9. node.js - node_moduls太多了10. python - 关于ACK标志位的TCP端口扫描的疑惑?
