关于数据对比的问题。。。求SQL语句!!

summerice20 2009-05-18 11:30:13
有两张表
A表里记录的全部都是网址
URL
http://123aidushu.net
http://qq123.456.789.com
http://www.aidushu.net
http://www.aiyoo.net
http://www.alanga.net
http://www.an188.com
http://www.ankty.com
http://www.av113.com
http://www.av115.com
http://www.baidu345.com
http://www.bobcn.net
http://www.boliwo.com
http://www.cctv8.net
http://www.cctv8.net.cn
http://%77%77%77%2E%73%6F%6E%67%71%71%34%2E%63%6E/%71%71%31%31%2E%68%74%6D
http://0.11xp.com
http://sale.jinti.com/2598/2/92008/2098840.htm
http://0.sqwyt.com
http://007sf.cn
http://010.waokao.cn
http://022net.com/2008/6-26/42325336273760.html
http://023china.cn
http://218.87.32.244/webRegister/editInfo/addpic.aspx?flag=photo
http://03136.com
http://0321b.cn
http://0358.com.cn
http://0371cn.cn
http://040828.gxtupian.cn
http://050520.cn

B表里记录的全部都是网址的关键字
url
icafe8.com
.gov.cn
qq500.com
ssjj.com
hao123.com
funshion.com
175pt.com
netease.com
2sdo.com
kaixin001.com
56.com
fzl8.com
zqzone.cn
1212112.com
7m.cn
ld12.com
qqgexing.com
xj002.net

现在需要将两张表做对比,找出A表中有,而B表中没有的。。
比如说A表中http://022net.com/2008/6-26/42325336273760.html的这条记录,而B表有022net.com这个字段,那么这条记录将不返回数据集。
...全文
238 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
rmini 2009-05-19
  • 打赏
  • 举报
回复
select * from A where not exists(select 1 from B where charindex(b.url,a.URL)>0)
SQL77 2009-05-18
  • 打赏
  • 举报
回复
SELECT A.* FROM TA A ,TB B WHERE CHARINDEX(B.URL,A.URL)>0
百年树人 2009-05-18
  • 打赏
  • 举报
回复
select 
*
from
A
where
not exists(select 1 from B where charindex(b.url,a.URL)>0)
--小F-- 2009-05-18
  • 打赏
  • 举报
回复
select A.url from A 
where not exists(select 1 from A,B where A.url like '%B.url%')
jia_guijun 2009-05-18
  • 打赏
  • 举报
回复
select a.* from a where not exists(select 1 from b where charindex(b.url,a.url)>0)
Jane_64 2009-05-18
  • 打赏
  • 举报
回复
select A.url from A
where not exists(select A.url from A,B where A.url like '%B.url%')
jia_guijun 2009-05-18
  • 打赏
  • 举报
回复
select a.* from a where exists(select 1 from b where charindex(b.url,a.url)=0)
水族杰纶 2009-05-18
  • 打赏
  • 举报
回复
--TRY
SELECT A.* FROM TA A ,TB B WHERE PATINDEX('%'+B.URL+'%',A.URL)=0
Leshami 2009-05-18
  • 打赏
  • 举报
回复

declare @talbe_URL table(URL varchar(200))
insert into @talbe_URL select 'http://123aidushu.net'
union all select 'www.an188.com'
union all select 'http://qq123.456.789.com'
union all select 'http://www.aidushu.net'
union all select 'http://022net.com/2008/6-26/42325336273760.html'
union all select 'http://www.56.com'

declare @table_URL_Key table(keyword varchar(50))
insert into @table_URL_Key select 'icafe8.com'
union all select 'qq500.com'
union all select '022net.com'
union all select '56.com'
--select * from @table_URL_Key

select * from @talbe_URL a where not exists
(select * from @table_URL_Key b where charindex(b.keyword,a.url)>0)

/*
http://123aidushu.net
www.an188.com
http://qq123.456.789.com
http://www.aidushu.net
*/
jia_guijun 2009-05-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 jia_guijun 的回复:]
SQL codeselecta.*fromawherenotexists(select1frombwherecharindex(b.url,a.url)>0)
[/Quote]


--请验证一下,我认为是正确的。
summerice20 2009-05-18
  • 打赏
  • 举报
回复
好像以上运行出来的结果都不对呢。。。怎么A表里的数据运算后跟很运算前是一样的。。。根本就没有过滤掉。。。。。。。
missilemy 2009-05-18
  • 打赏
  • 举报
回复
用左外联接会不会稍快?
参考:
select a.url from a left join b on (charindex(b.url,a.url,0)>0)
where b.url is null
summerice20 2009-05-18
  • 打赏
  • 举报
回复
楼上的那个运行很慢,,最快的就是SELECT A.* FROM TA A ,TB B WHERE PATINDEX('%'+B.URL+'%',A.URL)=0
可是这句改成返回同样的数据集的时候运行也很慢!!
百年树人 2009-05-18
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 summerice20 的回复:]
如果A表中http://022net.com/2008/6-26/42325336273760.html的这条记录,而B表有022net.com这个字段,那么这条记录将返回数据集。这样的情况怎么做运算呢??有什么函数可以统计!!!
[/Quote]

select 
*
from
A
where
exists(select 1 from B where charindex(b.url,a.URL)>0)
summerice20 2009-05-18
  • 打赏
  • 举报
回复
如果A表中http://022net.com/2008/6-26/42325336273760.html的这条记录,而B表有022net.com这个字段,那么这条记录将返回数据集。这样的情况怎么做运算呢??有什么函数可以统计!!!

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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