比如有张表,两个字段,
客户    特征码
------------------------------
K1     T1
K2     T1
K3     T1K1     T2
K2    T2 
K4    T2K1    T3
K2    T3
K3    T3
根据以上数据,想得到以下结果,
K1 与K2 拥有共同有特征码 T1,T2,T3 , 相似度最高,如相似度为3
K1,K2,K3  拥有共同有特征码 T1,T3, 相似度较高,如相似度为2有没自动聚合语句,按相似度高低情况排序出来? 

解决方案 »

  1.   

    with v1 as (
    select khh,wmsys.wm_concat(distinct tzm) tzm from   Table1 group by khh 
    )
    select a.khh,b.khh khh1,a.tzm,b.tzm tzm1
    ,UTL_MATCH.Edit_Distance_Similarity(a.tzm,b.tzm) xsd
    from v1 a ,v1 b 
    where a.khh<>b.khh  但比如仅只有1个特征码相同,相似度为100% ,比3个特征码中有两个相同的高,
    能否取出相同的特征码拿来做权数
      

  2.   


    create table t3(a varchar2(30),b varchar2(30));insert into t3 values('K1','T1');
    insert into t3 values('K2','T1');
    insert into t3 values('K3','T1');
    insert into t3 values('K1','T2');
    insert into t3 values('K2','T2');
    insert into t3 values('K4','T2');
    insert into t3 values('K1','T3');
    insert into t3 values('K2','T3');
    insert into t3 values('K3','T3');commit;
    select * from t3;select *
      from (select s, to_char(wm_concat(b)), count(1) as cou
              from (select t3.a, t3.b, k.a, t3.a || k.a as s
                      from t3, t3 k
                     where t3.a != k.a
                       and t3.b = k.b)
             group by s)
     order by cou desc半成品的sq,看看能满足你的需求不