tb1:

tb2:

查詢表1中所有的姓名在表2中出現的次數。
uj5u.com熱心網友回復:
select tb1.姓名,
count(case when instr(tb2.姓名,tb1.姓名)>1 then 1 else 0 end)
from tb1,tb2
group by tb1.姓名;
uj5u.com熱心網友回復:
select tb1.姓名,
count(case when instr(tb2.姓名,tb1.姓名)>0 then 1 else 0 end)
from tb1,tb2
group by tb1.姓名;
錯了,是大于0
uj5u.com熱心網友回復:
用instr的話,先拼上逗號在匹配 假如 表2有個 李易峰, 表1 有個 李易 這樣也會匹配上的. instr (', 李易峰,',', 李易,') 這樣就沒問題了uj5u.com熱心網友回復:
drop table test1;drop table test;
create table test(姓名 varchar2(20));
insert into test values('a');
insert into test values('b');
insert into test values('d');
insert into test values('c');
create table test1(id number(2),manageuser varchar(40));
insert into test1 values(1,'a,b,c');
insert into test1 values(2,'a,b');
insert into test1 values(3,'a,b,c,d');
insert into test1 values(4,'a,c');
select tb1.姓名,count(*)
from test tb1,
(select regexp_substr(manageuser, '[^,]+', 1, level) 姓名
from test1 tb2
connect by level <= regexp_count(manageuser, '[,]') + 1
and prior id = id
and (prior dbms_random.value) is not null) tb2
where tb1.姓名 = tb2.姓名
group by tb1.姓名
uj5u.com熱心網友回復:
借用樓上資料with tt as(
select wm_concat(t1.manageuser) mm from test1 t1)
select t.姓名, length(t2.mm)-length(replace(t2.mm,t.姓名,'')) 次數
from test t,tt t2
uj5u.com熱心網友回復:
select test.姓名,sum(case when instr(test_1.manageuser,test.姓名)>0 then 1 else 0 end)
from test,test_1
group by test.姓名;
uj5u.com熱心網友回復:
欄位左右加上單引號就完美了轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/110566.html
標籤:高級技術
上一篇:分組查詢
