表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
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
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
*/
别光顶呀 dawugui 帮忙想下
我怎么感觉就像是做一个order by ...
select * from #tb as t where flag=1 and (select count(1) from #tb where flag<>1 and title like t.title+'%')>0
如果是完全匹配就基本无解了.
完全匹配 这样不行吗 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 是如何用呢?帮忙解释下