日期:2014-05-19  浏览次数:20576 次

求一个比较有难度的SQL语句 当场给分~~
A     id             title      
        1             abc
        2             def
        3             cds

B     id             key
        1               a
        2               d
        3               g

现在要查出A中title中所有含有key字段的信息   如:如果是a   就查询到
        1           abc
如果是d     查询到:
        1           def
        2           cds

这种情况sql语句怎么写?

------解决方案--------------------
create table A ( id int, title varchar(10))
insert A
select 1, 'abc ' union all
select 2, 'def ' union all
select 3, 'cds '

create table B ( id int, skey varchar(10))
insert B
select 1, 'a ' union all
select 2, 'd ' union all
select 3, 'g '

select B.skey,A.* from B,A where charindex(B.skey,A.title)> 0

drop table A
drop table B
------解决方案--------------------
paoluo(一天到晚游泳的鱼) ( ) 信誉:100 2007-07-18 14:29:05 得分: 0


這個意思?


Select A.* From A Inner Join B On A.title Like '% ' + B.[key] + '% ' Where A.[key] = 'a '
Select A.* From A Inner Join B On A.title Like '% ' + B.[key] + '% ' Where A.[key] = 'd '
====================================================
正解```这样也可以````
Select A.* From A Inner Join B On A.title Like '% ' + B.[key] + '% '



------解决方案--------------------
delete a from tableA as a
inner join tableB as b on charindex(b.[key],a.title) > 0
------解决方案--------------------
或者

Delete A From A Inner Join B On CharIndex(B.[key], A.title) > 0 Where A.[key] = 'a '
Delete A From A Inner Join B On CharIndex(B.[key], A.title) > 0 Where A.[key] = 'd '