选择不同记录的优化方式

时间:2016-12-15 09:28:00

标签: sql hive apache-spark-sql

我在hive中有一个包含23列的表,其中5列构成复合主键。 什么是从表中选择所有不同记录的最佳优化方法。

2 个答案:

答案 0 :(得分:1)

select  *

from   (select  t.*
               ,count(*) over (partition by Col1,Col2,Col3,Col4,Col5) as cnt

        from    tablename t 
        ) t

where   t.cnt = 1
;

答案 1 :(得分:0)

将group by语句与where where语句一起使用count(1)> = 1,这将根据您的复合键为您提供不同的记录。

喜欢

Select Col1,Col2,Col3,Col4,Col5,Count(1) from tablename group by Col1,Col2,Col3,Col4,Col5 having Count(1)>=1
相关问题