Mysql
 sql >> Base de données >  >> RDS >> Mysql

comment trouver les valeurs nécessaires d'une variable unique à partir de deux tables

Peut-être quelque chose comme ça

SELECT hops.hop_route,count(plan_info_upload.*) as no_of_2G, SUM(plan_info_upload.2G_bw) as total_2G_bw FROM(
SELECT DISTINCT (hops.hop_route) as hop_route FROM (
                SELECT DISTINCT hop_1 as hop_route FROM hop_without_router
                 UNION 
                SELECT DISTINCT hop_2 as hop_route FROM hop_without_router
                 UNION 
                SELECT DISTINCT hop_3 as hop_route FROM hop_without_router
                 UNION 
                SELECT DISTINCT hop_4 as hop_route FROM hop_without_router
                 UNION 
                ......
                SELECT DISTINCT hop_9 as hop_route FROM hop_without_router) as hops ) as unique_hops )  LEFT JOIN plan_info_upload ON hops.hop_route = plan_info_upload.route_path