简体   繁体   English

Oracle:使用 where 子句选择重复项?

[英]Oracle: Selecting Duplicates with where clause?

我有一个问题:为什么我不能只使用以下 SQL 查询从PERSON表中获取唯一电子邮件地址的列表?

SELECT NOT DISTINCT Email FROM PERSON

I think the easiest and common way to achieve this is with grouping by the Email column and then keep the records having count = 1.我认为实现这一点的最简单和常见的方法是按电子邮件列分组,然后保留计数 = 1 的记录。

SELECT Email, COUNT(Email)
FROM PERSON
GROUP BY Email
HAVING COUNT(Email) > 1;

NOT DISTINCT is not working because it is not a valid expression. NOT DISTINCT 不起作用,因为它不是一个有效的表达式。 DISTINCT is used to return only different values, so NOT before it is not working as you expect. DISTINCT 仅用于返回不同的值,因此在它没有按预期工作之前不会。

You asked to get a list of unique eMail addresses , which is done by:您要求获取唯一电子邮件地址列表,这是通过以下方式完成的:

SELECT DISTINCT(Email) FROM PERSON;

Standard SQL does not have NOT DISTINCT or anything like that.标准 SQL 没有NOT DISTINCT或类似的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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