zoukankan      html  css  js  c++  java
  • mysql 表关联时执行顺序

    left join  左连接

     1 with temp1 as (
     2 select 1 as id ,12 as num union 
     3 select 2 as id ,13 as num union 
     4 select 3 as id ,12 as num union 
     5 select 4 as id ,14 as num union 
     6 select 5 as id ,12 as num union 
     7 select 6 as id ,16 as num  
     8 ), temp2 as (
     9 select 1 as id ,'a' as var union 
    10 select 2 as id ,'b' as var union 
    11 select 3 as id ,'c' as var union 
    12 select 4 as id ,'a' as var union 
    13 select 5 as id ,'b' as var union 
    14 select 6 as id ,'f' as var  
    15 )
    16 select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id
    View Code

    left join  左连接 (on 中加条件)

    说明:先关联, 再过滤 ;

     1 with temp1 as (
     2 select 1 as id ,12 as num union 
     3 select 2 as id ,13 as num union 
     4 select 3 as id ,12 as num union 
     5 select 4 as id ,14 as num union 
     6 select 5 as id ,12 as num union 
     7 select 6 as id ,16 as num  
     8 ), temp2 as (
     9 select 1 as id ,'a' as var union 
    10 select 2 as id ,'b' as var union 
    11 select 3 as id ,'c' as var union 
    12 select 4 as id ,'a' as var union 
    13 select 5 as id ,'b' as var union 
    14 select 6 as id ,'f' as var  
    15 )
    16 -- select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id
    17 select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id and t1.num=12 
    18 -- select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id where t1.num=12
    View Code

    left join  左连接  (末尾 where 条件)

    说明:最后过滤

     1 with temp1 as (
     2 select 1 as id ,12 as num union 
     3 select 2 as id ,13 as num union 
     4 select 3 as id ,12 as num union 
     5 select 4 as id ,14 as num union 
     6 select 5 as id ,12 as num union 
     7 select 6 as id ,16 as num  
     8 ), temp2 as (
     9 select 1 as id ,'a' as var union 
    10 select 2 as id ,'b' as var union 
    11 select 3 as id ,'c' as var union 
    12 select 4 as id ,'a' as var union 
    13 select 5 as id ,'b' as var union 
    14 select 6 as id ,'f' as var  
    15 )
    16 -- select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id
    17 -- select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id and t1.num=12 
    18 select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id where t1.num=12
    View Code

    left join  左连接  ( on 中加条件 & 末尾 where 条件)

     1 with temp1 as (
     2 select 1 as id ,12 as num union 
     3 select 2 as id ,13 as num union 
     4 select 3 as id ,12 as num union 
     5 select 4 as id ,14 as num union 
     6 select 5 as id ,12 as num union 
     7 select 6 as id ,16 as num  
     8 ), temp2 as (
     9 select 1 as id ,'a' as var union 
    10 select 2 as id ,'b' as var union 
    11 select 3 as id ,'c' as var union 
    12 select 4 as id ,'a' as var union 
    13 select 5 as id ,'b' as var union 
    14 select 6 as id ,'f' as var  
    15 )
    16 select  * from temp1 t1 left join temp2 t2 on t1.id =t2.id and t1.num=12  where  t1.num=12
    View Code

  • 相关阅读:
    Codeforces 845E Fire in the City 线段树
    Codeforces 542D Superhero's Job dp (看题解)
    Codeforces 797F Mice and Holes dp
    Codeforces 408D Parcels dp (看题解)
    Codeforces 464D World of Darkraft
    Codeforces 215E Periodical Numbers 容斥原理
    Codeforces 285E Positions in Permutations dp + 容斥原理
    Codeforces 875E Delivery Club dp
    Codeforces 888F Connecting Vertices 区间dp (看题解)
    Codeforces 946F Fibonacci String Subsequences dp (看题解)
  • 原文地址:https://www.cnblogs.com/linbo3168/p/13359651.html
Copyright © 2011-2022 走看看