简体   繁体   English

我如何结合这些mysql语句

[英]How do I combine these mysql statements

I am currently doing this: 我目前正在这样做:

    SELECT SS.service_name , SS.id, SH.shortcode FROM smsc_app_db.service SS
 INNER JOIN shortcode SH ON SS.confirmation_shortcode = SH.id;

    SELECT count(service_id) FROM smsc_app_db.service_status 
where smsc_app_db.service_status.service_id = ?;

After running the first select, I get the result in java, then for each row of the ResultSet, I use the SS.ID value to count the number of subscribers to that service on the service_status table (using the second statement) 运行第一个选择后,我得到的结果是java,然后对于ResultSet的每一行,我使用SS.ID值来计数service_status表上该服务的订阅者数量(使用第二条语句)

But I would like to combine the 2 statements into one. 但是我想将这两个语句合并为一个。

Is it possible to make the select count(service_id) 是否可以进行select count(service_id)

a column in the first select statement? 第一个选择语句中的一列?

eg if the result of 例如,如果

select count(service_id).... is stored in subscriber_base select count(service_id)....存储在subscriber_base

    SELECT SS.service_name , SS.id, SH.shortcode, subscriber_base FROM 
smsc_app_db.service SS INNER JOIN shortcode SH ON SS.confirmation_shortcode = SH.id;

join the service_status table to the existing query and aggregate to get the counts. join的SERVICE_STATUS表到现有的查询和汇总得到的计数。

SELECT SS.service_name, SS.id, SH.shortcode, count(*) subscriber_base 
FROM smsc_app_db.service SS 
INNER JOIN shortcode SH ON SS.confirmation_shortcode = SH.id
INNER JOIN smsc_app_db.service_status sstat ON sstat.service_id = SS.id
GROUP BY SS.service_name, SS.id, SH.shortcode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM