mysql group中能否使用两个count呢
问题描述
问题解答
回答1:其实最好写明你的表结构,以下答案基于你提供的有限信息:
select district as 行政区,count(1) as 小区数 -- 我默认你每个小区时一条记录,且无重复, sum(if(idNB = 1 ,1 ,0)) as 高档小区数 -- 假设高档小区的idNB标记为1from table_name group by district其实 sum(if(idNB = 1 ,1 ,0)) 也可以替换成count(idNB = 1 or null)回答2:
mysql不支持分析函数:
select t1.district, (select count(t2.xiaoqu) from table t2 where t2.district=t1.district) count_xiaoqu, (select count(t2.idNB) from table t2 where t2.district=t1.district) count_idNBfrom table t1
分析函数的写法:
select district, count(xiaoqu) over (district) count_xiaoqu, count(idNB) over (district) count_idNBfrom table回答3:
我这边说下我的思路吧,使用MySQL将区内的高端小区和非高端小区统计出来
select district,idNB,count(*) from xx GROUP BY district,idNB
然后区内小区的总数再由服务端这边自己处理计算。
相关文章:
1. html5 - 请问一下写H5的时候 你们都是兼容那些手机2. node.js - npm安装模块时,在cmd上显示的是一条白线,白线前面是一天反斜线转圈圈,然后就出现npm ERR错误了,求帮助,谢谢3. android - java tm platform se binary 占用很多内存4. java - Spring MVC 映射请求问题5. javascript - Vue $refs 为什么无法获取组件对象6. php - 注册验证邮箱失效后操作问题7. mysql自动提交的问题8. python 函数名之后 有一个箭头 这是什么作用?9. java - 做一个视频播放器,想实现一个功能,如果3秒不点击屏幕任何,则下方一个界面布局(显示按钮那些的)自动消失。10. clone - git sourceTree克隆仓库时,都不停弹出Password Required弹窗,即时输入正确的git账号密码还是弹出

网公网安备