tb_contact是通讯录表
表结构是
id                      主键



loginid                 拥有者编号
openid                  共享列表(共享给n个好友,比如 user1  user2 user3 )分割的方式分开。功能是。先多选通讯录,点击共享按钮弹出好友列表,多选好友点确定。这些通讯录的openid修改成好友的散列。但这样的情况怎么过滤。
比如:
user1 有contact1,contact2通讯录contact1和contact2已经共享了user2,user3
user1 又点击contact1,contact2点共享时,弹出好友列表中不应该user2和user3。原理是这样的。看看怎么过滤点已经是共享了的好友呢???

解决方案 »

  1.   

    user1 点 contract 1通讯录 要显示的user 就是不包括user2和user3的是吧。也就是select user form 用户表 where user not in (select user from contract 1 where 拥有者=user1)
      

  2.   

    思路是通过replace(openid,已经共享的user,''),再处理产生的多余的分隔符....
      

  3.   

     substr(tt.str,instr(','||tt.str||',',',',1,rn),
    instr(','||tt.str||',',',',1,rn+1)-instr(','||tt.str||',',',',1,rn) )as str_new用上面的语句把tb_contact中的openid拆成字典表再做关联,这样即可判断。
      

  4.   

    Using below SQL to join share_user(openid) which is primary key in foreign user tables by not exists.
    SQL> select tid,
      2         loginid,
      3         substr(',' || openid || ',',
      4                instr(',' || openid || ',', ',', 1, rn) + 1,
      5                instr(',' || openid || ',', ',', 1, rn + 1) -
      6                instr(',' || openid || ',', ',', 1, rn) - 1) as new_openid
      7    from tb_contract,
      8         (select rownum rn
      9            from all_objects
     10           where rownum <=
     11                 (select max(length(openid) - length(replace(openid, ','))) + 1
     12                    from tb_contract)) ao
     13   where instr(',' || openid, ',', 1, rn) > 0;       TID    LOGINID NEW_OPENID
    ---------- ---------- ----------------------
             1          2 2
             2          3 2
             3          5 1
             1          2 3
             2          3 3
             3          5 5
             2          3 4
             3          5 7
             3          5 8
             3          5 910 rows selected