二维GROUP BY
生活随笔
收集整理的這篇文章主要介紹了
二维GROUP BY
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
上午參加了個計算機英語三級考試,回來后BA同事讓幫忙統計數據。可能剛考完試思維比較混亂, 整理了好大一會沒有想明白怎么寫。
最后掙扎了快一個小時終于想起來,記下來留個備份;
select store_no, brand_code, count(distinct t.dealer_code)from juran.emall_booth_contract tgroup by store_no, brand_codehaving count(distinct t.dealer_code) > 1如果統計表數量則是:selelct count(*) from emall_booth_contract;
如果統計門店數量:select store_no,count(*) from emall_booth_contract;
統計門店數量大于1:select store_no from emall_booth_contract group by store_no having count(*) >1;
當時怎么想不明白怎么統計門店下品牌數量,其實select兩列的話,是按照那兩列分組,統計沒組下有多少個品牌;
加上distinct進行重復值去除。
having條件是把每組下數量大于1的結果查出;
轉載于:https://www.cnblogs.com/xiaoheshang/p/4566028.html
總結
以上是生活随笔為你收集整理的二维GROUP BY的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdu5247 找连续数
- 下一篇: 变量和字符串