我需要获取每一行的最新版本,以免重复数据。 “ _sdc_sequence”是复制期间附加到记录的unix时代,它确定行的所有版本的顺序。 我想每天从每个广告系列中获取费用和展示次数
我尝试使用INNER JOIN,但无法获取数据。当我尝试使用“帐户”和“客户端名称”作为属性(每行具有相同的客户端名称和帐户)时,我在成本和展示次数上都感到不满意。也许属性是错误的
SELECT DISTINCT day, cost, impressions, campaign
FROM `adxxxxx_xxxxxxxx` account
INNER JOIN (
SELECT
MAX(_sdc_sequence) AS seq,
campaignid
FROM `adxxxxx_xxxxxxxx`
GROUP BY campaignid) clientname
ON account.campaignid = clientname.campaignid
AND account._sdc_sequence = clientname.seq
ORDER by day
还有另一种方法吗?或如何解决? 谢谢
答案 0 :(得分:0)
#standardSQL
SELECT row.* FROM (
SELECT ARRAY_AGG(t ORDER BY _sdc_sequence DESC LIMIT 1)[OFFSET(0)] row
FROM `adxxxxx_xxxxxxxx` t
GROUP BY campaignid
)