17,377
社区成员
发帖
与我相关
我的任务
分享
Select Menu_List,(Select Count(aid)
From (select distinct aid from a) T1
Where INSTR(T2.Menu_List,AID) > 0) FROM T2
XD,下面是两种方法,第一种方法(我最先写的那个)优化了一下,第二种方法是与第一种方法不同的思路,我试了一下第二种的方法速度快一些,你可以试一下看 ..
然后相关字段建索引 .. Just try it ..
SQL> select distinct
2 new_Industry
3 from (
4 select decode(sign(instr('|'||Menu_List,AID,1,rn)),1,Industry,0) as new_Industry
5 from B,
6 A,
7 T
8 where instr('|'||Menu_List,'|',1,rn+1)-instr('|'||Menu_List,'|',1,rn) > 0
9 )tt
10 where new_Industry > 0;
NEW_INDUSTRY
------------
1
2
SQL>
SQL> select distinct
2 Industry
3 from A,
4 (
5 select B.id,
6 substr('|'||Menu_List,
7 instr('|'||Menu_List,'|',1,rn)+1,
8 instr('|'||Menu_List,'|',1,rn+1)-instr('|'||Menu_List,'|',1,rn)-1) as new_Industry
9 from B,
10 tt
11 where instr('|'||Menu_List,'|',1,rn+1)-instr('|'||Menu_List,'|',1,rn) > 0
12 )AB
13 where A.AID = AB.new_Industry;
INDUSTRY
----------
1
2