简体   繁体   中英

SQL join is duplicating data

`SELECT 
t2.Date, 
t2.CampaignID,
t1.CampaignName,
SUM(t2.Impressions) AS Impressions,
SUM(t2.Clicks) AS Clicks,
SUM(t2.Cost/1000000) AS Cost,
SUM(t2.Conversions) AS Conversions
FROM "table_1.Campaign_5333142620" t1
LEFT JOIN "table_1.CampaignBasicStats_5333142620" t2 USING (CampaignId)
WHERE t2.DATE = '2022-02-09' AND t2.CampaignID = 15917662281
GROUP BY t2.Date, t1.CampaignName, t2.CampaignID
LIMIT 10`

Hey all,

I am having an issue whereby my data is exactly duplicated for each row when performing this join. Without the join, using the table "CampaignBasicStats", the data is not duplicated, but joining to the other table creates the duplication...

Any help greatly appreciated!

You can try on this way..

SELECT t2.Date, t2.CampaignID, t1.CampaignName, SUM(t2.Impressions) AS Impressions, SUM(t2.Clicks) AS Clicks, SUM(t2.Cost/1000000) AS Cost, SUM(t2.Conversions) AS Conversions FROM "table_1.Campaign_5333142620" t1 LEFT JOIN "table_1.CampaignBasicStats_5333142620" t2 ON t2.CampaignId = t1.CampaignId AND t2.DATE = '2022-02-09' AND t2.CampaignID = 15917662281 GROUP BY t2.Date, t1.CampaignName, t2.CampaignID LIMIT 10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM