嗨,我无法正确计算此问题。我正在尝试计算具有不同名字和/或不同姓氏的重复电子邮件。 (即 123 @ .com山姆 123 @ .com ben 我需要一份重复的电子邮件) 我正在使用2张桌子。 email_address位于mrtcustomer.customer_email表中,名字和姓氏位于mrtcustomer.customer_master表中
我的代码
SELECT COUNT(*)
FROM
(SELECT e.customer_master_id, email_address, customer_first_name, customer_last_name,
ROW_NUMBER() OVER (PARTITION BY EMAIL_ADDRESS ORDER BY CUSTOMER_FIRST_NAME) RN
FROM mrtcustomer.customer_email e
JOIN mrtcustomer.customer_master t ON e.customer_master_id = t.customer_master_id
WHERE t.customer_first_name IS NOT NULL
AND t.customer_last_name IS NOT NULL
AND customer_FIRST_NAME != 'Unknown'
AND customer_LAST_NAME != 'Unknown'
GROUP BY e.customer_master_id, email_address, customer_first_name, customer_last_name
ORDER BY 1 DESC)
WHERE RN > 1
我猜测我的WHERE子句是错误的。
答案 0 :(得分:1)
我会从这样的事情开始:(编辑以反映编辑)
select email_address
, count( distinct customer_first_name ) f
, count( distinct customer_last_name ) l
from customer_email e, customar_master m
where e.customer_master_id = m.customer_master_id
group by email_address
然后,如果任一名称列是> 1你有问题 - 所以包装类似于:
select email_address from
(
select email_address
, count( distinct customer_first_name ) f
, count( distinct customer_last_name ) l
from customer_email e, customar_master m
where e.customer_master_id = m.customer_master_id
group by email_address
)
where fn > 1 or ln > 1
答案 1 :(得分:0)
识别不同的fname,lname,电子邮件记录...... 然后通过电子邮件分组(有多个记录)...... 然后指望一下。
-- count
SELECT COUNT(DISTINCT email_address)
FROM
(
-- group by email , find where there is more than one distinct record for each email
SELECT email_address
FROM
(
-- get distinct Fname, Lname, Email combinations in derived table
SELECT customer_first_name , customer_last_name, email_address
FROM mrtcustomer.customer_email
JOIN mrtcustomer.customer_master t ON e.customer_master_id = t.customer_master_id
WHERE t.customer_first_name IS NOT NULL
AND t.customer_last_name IS NOT NULL
AND customer_FIRST_NAME != 'Unknown'
AND customer_LAST_NAME != 'Unknown'
GROUP BY 1,2,3
) foo
GROUP BY 1
HAVING COUNT(*)>1
) bar