求解一个查询语句

u010667428 2017-12-18 06:48:22
select a from A
where a like (select b from b)
大概是这个意思,要怎么写啊???


如图 要查询结果 (一个表中id另一个表中有相同的类似的 都去除)
...全文
205 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
吉普赛的歌 版主 2017-12-19
  • 打赏
  • 举报
回复
借一楼数据:
if OBJECT_ID(N'tempdb.dbo.#t1') is not null drop table #t1
create table #t1(id int)
insert into #t1
select 985 union all
select 456 union all
select 789 union all
select 112 union all
select 2135 union all
select 6132 
if OBJECT_ID(N'tempdb.dbo.#t2') is not null drop table #t2
create table #t2(id int)
insert into #t2
select 12 union all
select 78 

SELECT * FROM #t1 AS a WHERE NOT EXISTS (
	SELECT 1 FROM #t2 AS b WHERE CAST(a.id AS VARCHAR(50)) LIKE '%'+CAST(b.id AS VARCHAR(50)) +'%'
)
/*
id
985
456
2135
6132
*/
RINK_1 2017-12-18
  • 打赏
  • 举报
回复

if OBJECT_ID(N'tempdb.dbo.#t1') is not null
drop table #t1
go

create table #t1
(id int)

insert into #t1
select 985 union all
select 456 union all
select 789 union all
select 112 union all
select 2135 union all
select 6132 

if OBJECT_ID(N'tempdb.dbo.#t2') is not null
drop table #t2
go

create table #t2
(id int)

insert into #t2
select 12 union all
select 78 

select * 
from #t1 A
where not exists (select 1 from #t2 B where CHARINDEX(LTRIM(B.id),LTRIM(A.id))>0)


34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧