-- 1. 判断joinkey唯一性
-- 2. 如果不唯一, 判断joinkey在所需维度上的唯一性, 如果唯一, 则没问题(直接对所有所需维度取max即可, 然后根据连接条件group by), 如果不唯一, 需要找上游确认原因
-- joinkey唯一性判断
SELECT
ad_id AS ad_id,
ftime AS ftime,
COUNT( *) as num
FROM
fdm.fdm_szad_w_ad_info_day
WHERE
ftime >= '20180426'
AND platform_type = '京东直投'
AND media_type = '广点通'
GROUP BY
ad_id,
ftime
HAVING
num > 1
-- 在所需列上的唯一性判断
SELECT
所需维度1,
所需维度2,
joinkey,
COUNT( *) as num
FROM
fdm.fdm_szad_w_ad_info_day
WHERE
ftime >= '20180426'
AND platform_type = '京东直投'
AND media_type = '广点通'
GROUP BY
所需维度1,
所需维度2,
joinkey
HAVING
num > 1
-- 若在所需列上唯一, 则直接取max
SELECT
max(所需维度1),
max(所需维度2),
joinkey
FROM
table_name
GROUP BY
joinkey