表tb1
marc_no(pk)  flag     title             isbn   .....
1            2     4天爱                 7-80188-815-4
2            1     科学发展观              978-7-80230-793-3
5            1     科学发展                7-1012-5412-7
3            4     科学发展观              978-7-80230-709-4
4            3     科学发展观的经济学解释  7-5053-7707-8
.......
查询原则是 把 FLAG=1 的集合与flag<>1 的集合 按照titile匹配(完全或前方匹配) 列出来查询结果集合应该是这样的
marc_no(pk)  flag     title             isbn   .....
2            1     科学发展观              978-7-80230-793-3
5            1     科学发展                7-1012-5412-7

解决方案 »

  1.   

    --> 测试数据: #tb
    if object_id('tempdb.dbo.#tb') is not null drop table #tb
    create table #tb (marc_no int,flag int,title varchar(22),isbn varchar(17))
    insert into #tb
    select 1,2,'4天爱','7-80188-815-4' union all
    select 2,1,'科学发展观','978-7-80230-793-3' union all
    select 5,1,'科学发展','7-1012-5412-7' union all
    select 3,4,'科学发展观','978-7-80230-709-4' union all
    select 4,3,'科学发展观的经济学解释','7-5053-7707-8'select * from #tb as t where flag = 1 and exists (select 1 from #tb where flag<>1 and title like t.title+'%')/*
    marc_no     flag        title                  isbn
    ----------- ----------- ---------------------- -----------------
    2           1           科学发展观             978-7-80230-793-3
    5           1           科学发展               7-1012-5412-7
    */
      

  2.   

    不知道我说清楚了没 
    别光顶呀 dawugui 帮忙想下 
      

  3.   


    我怎么感觉就像是做一个order by ...
      

  4.   

    没有明白叙述,不过看结果应该是3楼的意思。顶了!
    select * from #tb as t where flag=1 and (select count(1) from #tb where flag<>1 and title like t.title+'%')>0
      

  5.   

    title 列是   整个字符串(例子中'科学发展' )的完全或前方匹配   
      

  6.   

    如果是前方匹配可以用 like '科学发展%'
    如果是完全匹配就基本无解了.
      

  7.   


    完全匹配 这样不行吗  exists  ?
    select * from MARC as t where MARC_USE_FLAG = '1' and exists (select * from MARC where MARC_USE_FLAG<>'1' and M_title = t.M_title)exists 是如何用呢?帮忙解释下