mysql:通过不同的值循环创建具有各种选择的过程

polhcujo  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(346)

我有一张这样的table

TIME  |STRCOUNTRY |STROPERATOR | NINCOMINGCALLS
300718|RUSSIA     |MTS         | 2
300718|RUSSIA     |Megafon     | 3
300718|UK         |Vodafone    | 1
300718|UK         |UKTele      | 3

这就是我想展示的结尾:呼叫接线员,按国家列出的所有接线员的总和

RUSSIA  |Megafon |  3
RUSSIA  |MTS     |  2
RUSSIA  |#       |  5
UK      |Vodafone|  1
UK      |UKTele  |  3
UK      |#       |  4

# | #      | 9

可以通过这样的查询接收

select * from TM_COMMON_STAT where strCountry = "RUSSIA" and TIME = "300718"

UNION

select STRCOUNTRY, '#' as STROPERATOR, SUM(NINCOMINGCALLS) as 'NINCOMINGCALLS' from TM_COMMON_STAT where strCountry = "RUSSIA" and TIME = "300718"

如何获得表中所有运算符(distinct strcountry+stroperator)的输出,并最终获得所有国家/地区(其中运算符=#)的最终总和?
谢谢你的帮助。

vsaztqbk

vsaztqbk1#

这是我的工作 GROUP BY...WITH ROLLUP .
试试这个

SELECT STRCOUNTRY, STROPERATOR, SUM(NINCOMINGCALLS) NINCOMINGCALLS
  FROM TM_COMMON_STAT
 WHERE <<<whatever filters you require >>>
 GROUP BY STRCOUNTRY, STROPERATOR WITH ROLLUP

相关问题