通过3个唯一的列消除重复项

时间:2019-04-04 16:45:33

标签: sql impala hue

经过几条with声明之后,我到了这一步,似乎无法消除所有重复项。使用HUE编辑器在Impala中工作。最终查询中有几列,但我想在前3列中没有重复的值。前三个应该是唯一的。

这是我目前正在尝试的代码:

SELECT Rank2.facility_attr0,Rank2.cygtime,Rank2.valve, Rank2.cod,Rank2.ref,Rank2.csgpsi,Rank2.tbgpsi,Rank2.linepsi,Rank2.opldf,Rank2.groff,Rank2.ntoff,Rank2.opcml,Rank2.optml,Rank2.cllow,Rank2.clflw,Rank2.clcrt,Rank2.aftfw,Rank2.cyvol,Rank2.arvt,Rank2.clmdp,Rank2.toton,Rank2.clliq
FROM Rank2
INNER JOIN (
    SELECT Rank2.facility_attr0,Rank2.cygtime,Rank2.valve
    ,row_number() OVER(PARTITION BY Rank2.facility_attr0,Rank2.cygtime,Rank2.valve ORDER BY Rank2.facility_attr0 ASC) as RowUnique
    FROM Rank2
    WHERE Rank2.rnk = 1
    ) as x
ON (x.facility_attr0=Rank2.facility_attr0 and x.cygtime = Rank2.cygtime and x.valve = Rank2.valve and x.RowUnique = 1)
ORDER BY Rank2.facility_attr0, Rank2.CygTIME ASC

以下是根据前三列未删除重复项的结果。可以看出17:03不断重复。

facility_attr0              cygtime  valve               cod    ref csgpsi
        192102  2019-03-24 17:03:00   OPEN  Tubing-Line Psid    245  465.6
        192102  2019-03-24 17:03:00   OPEN  Tubing-Line Psid    245  454
        192102  2019-03-24 17:03:00   OPEN  Tubing-Line Psid    245  459.8
        192102  2019-03-24 17:03:00   OPEN  Tubing-Line Psid    245  459.8
        192102  2019-03-24 17:03:00   OPEN  Tubing-Line Psid    245  461.7
        192102  2019-03-24 17:03:00   OPEN  Tubing-Line Psid    245  454

子查询似乎在对行进行正确编号。

0 个答案:

没有答案