结构是这样的,在公文表中有轮阅人,放在一个字段里如“张三|李斯|黄武”,然后用户若点击该公文后,会在B表中生成阅读记录,现在我对未阅读记录条数判断的sql如下,发现速度比较慢,总得4-5秒,现在总的记录才3000多条,如果以后多了肯定更慢,不知道大家有啥好建议??select id from oa_inform a where a.id not in (select informid from oa_inform_reader b where a.id=b.informid and name='张三) and lyr like '%张三%'  

解决方案 »

  1.   

    select id from oa_inform a 
    inner join oa_inform_reader b
    on a.id=b.informid
    where b.name='张三 and lyr like '%张三%' 
      

  2.   

    select id from oa_inform a
    left join oa_inform_reader b
    on a.id=b.informid
    where not b.name='张三 and lyr like '%张三%' and b.informid is null
      

  3.   

    什么问题?
    select id from oa_inform a
    left join oa_inform_reader b
    on a.id=b.informid
    where b.name<>'张三' and a.lyr like '%张三%' and b.informid is nullorselect id from oa_inform a
    left join (select * from oa_inform_reader where b.name<>'张三') b
    on a.id=b.informid
    where  a.lyr like '%张三%' and b.informid is null
      

  4.   

    你执行
    select id from oa_inform a
    left join oa_inform_reader b
    on a.id=b.informid
    where a.lyr like '%张三%' and b.informid is null看看结果,去掉了一个条件b.name='张三'
      

  5.   


    select id from oa_inform a left join oa_inform_reader b 
    on a.id=b.informid where a.lyr not like '%张三%' and b.name != '张三' 
      

  6.   

    将我数据结构说一下oa_infomid,title,content,lyr
    1,aaaa,bbbbb,张三 ¦李斯 ¦黄武
    2,aacaa,bbbddbb,张三 ¦李斯
    3,ss,bbbcdbb,张三 ¦李斯 ¦黄武
    4,aabbaa,bccbbbb,张三
    oa_inform_readerid,informid,name
    1,1,张三 
    2,1,李斯
    3,1,黄武 
    4,3,张三
    。。
      

  7.   

    select a.id,* from oa_infom a
    left join oa_inform_reader b
    on a.id=b.informid
    where a.lyr like '*张三*' and b.informid is null 用上述代码查询出ID为2、4的记录
      

  8.   


    出来的结果不正确啊,兄弟,是否有问题,写的sql
      

  9.   


    还是分表吧!做个中间表来关联这些人,这个是很有好处的,如果以后系统还要求各各人只能做各自不同的事,你这样的设计没法改了,性能上用like是肯定要慢一大截的