簡體   English   中英

Oracle 12c-選擇具有序列的記錄

[英]Oracle 12c - select records that have sequences

我有一個包含以下列的表格:

employee_id number (PK);
unique_emp_id varchar2(20);
emp_uid varchar2(20);

我想選擇所有重復的emp_uid ,其中至少一個unique_emp_id like '%-%'not like '%-%' 我怎樣才能做到這一點?

示例數據:

emp_uid   unique_emp_id
--------- -------------
12345.12  12345.12
12345.12  12345.12-1
12345.12  12345.12-2
12345.34  12345.34-1
12345.34  12345.34-2

結果數據:

emp_uid   unique_emp_id
--------  -------------
12345.12  12345.12
12345.12  12345.12-1
12345.12  12345.12-2

如果我理解正確的話, group byhaving解決這個問題:

select emp_uid
from t
group by emp_uid
having sum(case when unique_emp_id like '%-%' then 1 else 0 end) > 0 and
       sum(case when unique_emp_id not like '%-%' then 1 else 0 end) > 0;

我會用exists

select t.*
from table t
where exists (select 1 from table t1 where t1.emp_uid = t.emp_uid and t1.unique_emp_id like '%-%') and
      exists (select 1 from table t1 where t1.emp_uid = t.emp_uid and t1.unique_emp_id not like '%-%');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM