"account", "tax_year"및 기타 필드가있는 기존 table1이 있습니다. CONCAT (account, tax_year)의 빈도가 1이고 WHERE 절을 만날 때 table1의 레코드로 table2를 작성하려고합니다. 예를 들어PostgresSQL에서 Count를 기준으로 사용하는 방법
이 표는 다음과 같다 경우 :
account year
aaa 2014
bbb 2016
bbb 2016
ddd 2014
ddd 2014
ddd 2015
표 2는해야한다 : 나는 이틀에 보냈다
DROP TABLE IF EXISTS table1;
CREATE table2 AS
SELECT
account::text,
tax_year::text,
building_number,
imprv_type,
building_style_code,
quality,
quality_description,
date_erected,
yr_remodel,
actual_area,
heat_area,
gross_area,
CONCAT(account, tax_year) AS unq
FROM table1
WHERE imprv_type=1001 and date_erected>0 and date_erected IS NOT NULL and quality IS NOT NULL and quality_description IS NOT NULL and yr_remodel>0 and yr_remodel IS NOT NULL and heat_area>0 and heat_area IS NOT NULL
GROUP BY account,
tax_year,
building_number,
imprv_type,
building_style_code,
quality,
quality_description,
date_erected,
yr_remodel,
actual_area,
heat_area,
gross_area,
unq
HAVING COUNT(unq)=1;
: 여기
account year
aaa 2014
ddd 2015
내 스크립트입니다 하지만 여전히 올바른 방법을 찾아 낼 수는 없습니다. 도와 주셔서 감사합니다!
감사합니다! 원본 테이블에는 11,755,200 개의 행과 71 개의 행이 있습니다. 쿼리는 20 시간 동안 실행되었으며 여전히 실행 중입니다. 이 데이터 세트의 크기를 분석하는 데 너무 오래 걸리는 것이 일반적입니까? 나는 Postgres에 익숙하지 않다 – 12B01
쿼리는 참으로 비싸다. 서버의 RAM이 부족하여 메모리 스와핑이 발생할 가능성이 큽니다. 테이블 크기에 따라 특별한 방법을 사용해야합니다 (예 : where 절을 사용하여 데이터를 더 작은 논리 부분으로 나누어 단계별로 실행합니다. – klin