oracle sql 中多列 table 中一列的唯一值

Unique values of one column in a multiple column table in oracle sql

我想用另一个 table 的列创建一个新的 table。只应选择那些行,其中第 x 列具有唯一值。 x 列应包含 a.

列的修剪值

这是我的代码:

create table nodupli as 
    select distinct(regexp_replace(a,'[[:space:]]|[[:punct:]]','')) as x,
        B, 
        C, 
        D
    from table1
order by x;

如何仅包含 x 列中具有唯一值的那些行?

您可以将该查询与另一个只有 returns 唯一 x 值的查询连接起来,例如

select  x
from    table1
group by x
having count(*) = 1

结果查询将是

create table nodupli as 
select  regexp_replace(t1.a,'[[:space:]]|[[:punct:]]','') as x,
        t1.B, 
        t1.C, 
        t1.D
from    table1 t1
join    (
            select  regexp_replace(a,'[[:space:]]|[[:punct:]]','') as x
            from    table1
            group by regexp_replace(a,'[[:space:]]|[[:punct:]]','')
            having count(*) = 1
        ) t2
on      regexp_replace(t1.a,'[[:space:]]|[[:punct:]]','') = t2.x
order by x;

编辑

之前的 join 条件是错误的,因为 xselect 中计算列的别名,所以它在 "presentation-level"。实际的列名还是原来的,需要在join条件下使用。我编辑了我的查询,现在应该是正确的。