代码之家  ›  专栏  ›  技术社区  ›  Taimur Islam

SQL分区表别名

  •  0
  • Taimur Islam  · 技术社区  · 5 年前
    select t1.col1, t1.col2, t1.col3, t1.col4, t1.col5
    
    from (tab1.tab1_1 partition(p20191231)) t1 
    
    LEFT JOIN ( 
                select t2.col_1 AS col_1, t2.col_2
                from (tab2.tab2_2  partition (p20191231)) t2
                where date between '1-Dec-2019' and '31-Dec-2019')
                ON t1.col1 = col_1
    where 
            t1.col6 between '1-Dec-2019' AND '31-Dec-2019';
    

    我正在尝试连接两个表,其中两个表都是分区表。这需要时间,但输出不是连接结果。它只显示第一个表数据。是分区表的别名吗?我们如何为分区表使用别名??

    0 回复  |  直到 5 年前
        1
  •  0
  •   Md Ziaul Haque    5 年前

    Yo没有调用第二张表(t2)中的任何列。您可以遵循以下代码

    select t1.col1, t1.col2, t1.col3, t1.col4, t1.col5,t2.col_1,t2.col_2
    from tab1.tab1_1 partition(p20191231) t1 
    LEFT JOIN ( 
                select t2.col_1 AS col_1, t2.col_2
                from (tab2.tab2_2  partition (p20191231)) t2
                where date between '1-Dec-2019' and '31-Dec-2019') t2
                ON t1.col1 = col_1
    where 
            t1.col6 between '1-Dec-2019' AND '31-Dec-2019';
    

    甚至简化为

    select t1.col1, t1.col2, t1.col3, t1.col4, t1.col5,t2.col_1,t2.col_2
    from 
      tab1.tab1_1 partition(p20191231) t1, 
      tab2.tab2_2  partition(p20191231) t2
    where 
      t2.date between '1-Dec-2019' and '31-Dec-2019' and
      t1.col1 = col_1 and 
      t1.col6 between '1-Dec-2019' AND '31-Dec-2019';