sql >> Databasteknik >  >> RDS >> Mysql

hur man hittar nödvändiga värden för en unik variabel från två tabeller

Kan vara något sånt här

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



  1. Uppdateringar av JSON-fältet kvarstår inte i DB

  2. Infoga blob i Oracle-databasen med C#

  3. NHibernate IPreUpdateEventListener, IPreInsertEventListener sparas inte i DB

  4. Hur man frågar jsonb-arrayer med IN-operator