0

嗨,我无法为这个问题获得正确的计数。我正在尝试计算具有不同名字和/或不同姓氏的重复电子邮件。(即 123@.com sam 123@.com 本我需要计算该重复电子邮件的数量)我正在使用 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 子句是错误的。

4

2 回答 2

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
于 2013-05-08T20:16:25.030 回答
0

识别不同的 fname,lname,email 记录...然后按电子邮件分组(具有多个记录)...然后对此进行计数。


-- 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

于 2013-05-08T20:28:37.967 回答