久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

mysql group中能否使用兩個count呢

瀏覽:110日期:2022-06-18 11:22:13

問題描述

問題解答

回答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

然后區內小區的總數再由服務端這邊自己處理計算。

相關文章:
主站蜘蛛池模板: 芷江| 金山区| 木兰县| 印江| 阿巴嘎旗| 昆明市| 仪陇县| 屏南县| 宽城| 新源县| 湘潭市| 屯留县| 台江县| 黄浦区| 汕尾市| 固阳县| 宜州市| 阿瓦提县| 景德镇市| 陇川县| 嘉峪关市| 焦作市| 清丰县| 开江县| 平泉县| 鄂伦春自治旗| 许昌县| 齐齐哈尔市| 夹江县| 冷水江市| 台江县| 上蔡县| 五原县| 苗栗市| 富民县| 鞍山市| 南溪县| 灵丘县| 兴义市| 芜湖县| 双柏县|