2017-07-10 32 views
0

我在PostgreSQL內連接兩個表。一個表格是我的原始AdWords數據(adwords_final)。第二個表格僅僅是對需要報告的「廣告系列」列的引用。這些參考文獻僅在每個廣告系列中出現一次,而adwords數據包含每個廣告系列的多個條目,因爲存在日期的因素/列。內連接的輸出內重複

我用下面的查詢其輸出到csv文件

COPY (SELECT * FROM adwords_final INNER JOIN mk_kw ON "mk_kw"."Key" = "adwords_final"."Key") TO 'C:\Users\iantu\Desktop\Performance Marketing\Report Outputs\adwords_final.csv' WITH CSV HEADER; 

的問題是,我的新的CSV文件包含遠很多重複。我在這裏使用正確的命令還是應該切換到循環?

adwords內的列final;

Week Keyword state Keyword Campaign Ad group Status Max. CPC Impressions Interactions Interaction Types Interaction Rate Avg. Cost Cost Clicks Avg. position Conversions Quality score Ad relevance Landing page experience Expected clickthrough rate Qual. score (hist.) Ad relevance (hist.) Landing page experience (hist.) Expected clickthrough rate (hist.) Search Impr. share Match type First position CPC Top of page CPC First page CPC Impressions with average ctr Impressions with above average ctr Impressions with below average ctr Impressions with below average lp exp Impressions with average lp exp Impressions with above average lp exp Impressions with below average Ad Rel Impressions with average ad rel Impressions with above average ad rel QSxIMP Key 

列mk_kw內

​​

感謝

回答

0
FROM 'C:\Users\iantu\Desktop\Performance Marketing\Report 
Outputs\adwords_final.csv' DELIMITER ',' CSV HEADER encoding 'windows-1251'; 
COPY (SELECT DISTINCT * FROM adwords_final LEFT JOIN mk_kw ON "mk_kw"."Key" = 
"adwords_final"."Key") TO 'C:\Users\iantu\Desktop\Performance Marketing\Report 
Outputs\adwords_final.csv' WITH CSV HEADER;