如何使用 2 个表获取订阅者数量
how to get number of subscribers using 2 tables
我目前正在开发一个 java 应用程序,它可以让我了解每个移动网络运营商的订户数量。
为此,我创建了一个 table,其中包含我称之为指示符的所有运算符,它包含 3 行:国家、运算符和 mobile_prefix。
我的第二个 table,称为 subs 包含两行:mobile_prefix 和订阅者数量
我应该使用什么查询才能得到这样的结果:
Operator Country Number of Subscribers
SFR France 20000
T-Mobile USA 10250
Telia Sweden 5248
..
任何形式的帮助将非常感激。
谢谢!
select a.operator,a.country,b.number_of_subscriber from table1 a left join table2 b on a.mobile_prefix = b.mobile_prefix;
这是你想要的吗??
请检查
此查询需要 join
和 group by
。您想要使用 left join
——假设您想要所有运营商,甚至是那些没有订阅者的运营商:
select i.operator, i.country, count(s.mobile_prefix) as numsubs
from indicatifs i left join
subs s
on i.mobile_prefix = s.mobile_prefix
group by i.operator, i.country
order by numsubs desc;
试试这个方法
select a.country, a.operator, count(*) as subscriber
from indicatifs a
left join subs b
on a.mobile_prefix = b.mobile_prefix
group by a.operator, a.country
我目前正在开发一个 java 应用程序,它可以让我了解每个移动网络运营商的订户数量。 为此,我创建了一个 table,其中包含我称之为指示符的所有运算符,它包含 3 行:国家、运算符和 mobile_prefix。 我的第二个 table,称为 subs 包含两行:mobile_prefix 和订阅者数量 我应该使用什么查询才能得到这样的结果:
Operator Country Number of Subscribers
SFR France 20000
T-Mobile USA 10250
Telia Sweden 5248
.. 任何形式的帮助将非常感激。 谢谢!
select a.operator,a.country,b.number_of_subscriber from table1 a left join table2 b on a.mobile_prefix = b.mobile_prefix;
这是你想要的吗?? 请检查
此查询需要 join
和 group by
。您想要使用 left join
——假设您想要所有运营商,甚至是那些没有订阅者的运营商:
select i.operator, i.country, count(s.mobile_prefix) as numsubs
from indicatifs i left join
subs s
on i.mobile_prefix = s.mobile_prefix
group by i.operator, i.country
order by numsubs desc;
试试这个方法
select a.country, a.operator, count(*) as subscriber
from indicatifs a
left join subs b
on a.mobile_prefix = b.mobile_prefix
group by a.operator, a.country