2014-09-10 2 views
0

내가 auditrtailreference라는 이름의 테이블이있는 나는 다음과 같은 쿼리를 실행하여 일부 데이터를 가져 오는하고 있습니다detete 행 그들로부터 데이터를 가져 오는 후

SELECT t3.destinationid AS input, 
    t1.sourceid AS Raw, 
    t1.outtime::TEXT, 
    t6.destinationid AS out_file, 
    t4.outtime::TEXT AS out_time, 
    t1.bytes AS inbytes, 
    t6.bytes AS outbyte, 
    t5.cdrs AS inputcdrs, 
    t6.cdrs AS outputcdrs, 
    t6.partial_cdrs, 
    t6.duplicate_cdrs, 
    t6.discarded_cdrs, 
    t6.created_cdrs, 
    t6.corrupted_cdrs, 
    t6.created_files, 
    t6.duplicate_files, 
    t6.corrupted_files, 
    t6.partial_files, 
    t6.discarded_files, 
    t6.empty_files 
FROM auditrtailreference t1 
LEFT JOIN auditrtailreference t2 ON t2.sourceid = t1.destinationid 
    AND t2.event = '80' 
    AND t2.innodename LIKE 'SDP%_SFTP' 
LEFT JOIN auditrtailreference t3 ON t3.sourceid = t2.destinationid 
    AND t3.event = '68' 
LEFT JOIN auditrtailreference t4 ON t4.sourceid = t3.destinationid 
    AND t4.event = '67' 
    AND (
     t4.innodename LIKE 'SDP%_Collector' 
     OR t4.innodename LIKE 'SDP%_collector' 
     ) 
LEFT JOIN auditrtailreference t5 ON t5.sourceid = t4.destinationid 
    AND t5.event = '73' 
LEFT JOIN auditrtailreference t6 ON t6.destinationid LIKE t3.destinationid || '%' 
    AND t6.event = '68' 
    AND (
     t6.outnodename LIKE 'SDP%_distributer' 
     OR t6.outnodename LIKE 'SDP%_Arch' 
     OR t6.outnodename LIKE 'SDP%_distributor' 
     OR t6.outnodename LIKE 'SDP%_Distributor' 
     OR t6.outnodename LIKE 'SDP%_Distributer' 
     ) 
WHERE t1.event = '67' 
    AND t1.innodename LIKE 'SDP%_SFTP' 
    AND t3.destinationid LIKE '%' 
    AND t1.outtime >= '2014/09/09 00:00' 
    AND t1.outtime <= '2014/09/10 19:51' 
    AND t3.outnodename LIKE '%init_Dist'; 

지금은 내가 유효을 가져온있는 모든 행을 삭제해야 데이터 (여기서 유효한 데이터는 내가 가져온 모든 열이 null이 아니어야 함을 의미 함)

이제 파일의 형식으로 데이터를 수신하고 있기 때문에 내가 이것을하고있는 이유는 무엇입니까? 테이블, 이제 나는 백그라운드에서 데몬을 실행하여 필요한 데이터를 가져오고 다른 테이블에 삽입합니다. 내가 마지막 테이블에 삽입 한 초기 테이블의 모든 행을 제거하기 위해 필요한이 후

+0

내가 PostgreSQL을 데이터베이스를 사용하고 내 데몬은 얼랑 과정입니다 :) – Khanjarrr

+0

나는 당신이 당신의 SQL을 정리하면이 질문의 가독성이 먼 길을 갈 것이라고 생각합니다. 서식 지정은 친구입니다. – paqogomez

답변

0

당신은 당신의 테이블 (auditrtailreference)에서 기본 키를 식별해야합니다 그리고 당신은 SELECT 쿼리에서 삭제하려면 만들 수 있습니다

어쩌면이 예는 다음과 같습니다

DELETE FROM auditrtailreference 
WHERE ROW_ID IN 
    (select ROW_ID from auditrtailreference... JOIN .... WHERE...) 
+0

나는 그 테이블에 기본 키를 갖고 있지는 않지만 ......... 솔루션 덕분에 고마워. :) – Khanjarrr

+0

하지만 t1.sourceid가있다. 아마도이 쿼리의 고유 키일 수있다. –

+0

아니 내 친구는 그것의 고유하지 ..... 심지어 널 수도 있습니다 ...... 단지 1 질문 내 목적을 해결하기 위해 포스트 그레스에서 ctid를 사용할 수 있습니까? – Khanjarrr

관련 문제