如何在Netezza中删除这些记录(Aginity)

时间:2017-09-10 09:38:39

标签: oracle netezza aginity

我写了一个查询以识别重复记录。

如下。

WITH DUPS AS
  (SELECT A_SURVEYID,
    CAST(e_responsedate AS DATE) AS e_responsedate,
    E_LG_VM_SURVEY_TYPE_ENUM
  FROM TRANSIENT..INTERIM_NPS_SURVEY_MOBILE_RESULTS_20170909 a
  GROUP BY A_SURVEYID,
    CAST(e_responsedate AS DATE),
    E_LG_VM_SURVEY_TYPE_ENUM
 HAVING COUNT(*) > 1
  ),
  RANKED AS
  (SELECT R.DRS_RECORD_ID,
    R.A_SURVEYID,
    R.e_responsedate ,
    ROW_NUMBER() OVER ( PARTITION BY R.A_SURVEYID, CAST(R.e_responsedate AS DATE),
       R.E_LG_VM_SURVEY_TYPE_ENUM ORDER BY SUBSTR(R.DRS_RECORD_ID, INSTR(':', R.DRS_RECORD_ID, 37) + 1, 14) DESC,
       SUBSTR(R.DRS_RECORD_ID, INSTR(':', R.DRS_RECORD_ID, 32) + 1, 4) ASC ) AS DR
  FROM TRANSIENT..INTERIM_NPS_SURVEY_MOBILE_RESULTS_20170909 R
  INNER JOIN DUPS
  ON R.A_SURVEYID                    = DUPS.A_SURVEYID
  AND CAST(R.e_responsedate AS DATE) = DUPS.e_responsedate
  AND R.E_LG_VM_SURVEY_TYPE_ENUM     = DUPS.E_LG_VM_SURVEY_TYPE_ENUM
  )
 SELECT *
FROM TRANSIENT..INTERIM_NPS_SURVEY_MOBILE_RESULTS_20170909 F
INNER JOIN RANKED
ON F.DRS_RECORD_ID = RANKED.DRS_RECORD_ID
WHERE RANKED.DR     > 1

-

通过使用Above Query可以检索记录。(大约6000+)。

但我无法删除这些记录。

你可以帮我解决这个问题。

此致

Krish

1 个答案:

答案 0 :(得分:0)

你非常接近。在最后5行中,请改为:

li

应该工作:)

顺便说一句:我很确定这可以用更少的代码来完成,但这并不重要......