如何做同义查询呢?如查询福建,则出现闽的也搜索出来.

gyx999 2003-10-29 08:38:58
我想把同义词放在表table_keyword中,他们的wordID相同,表示同义
table_keyword
keyword wordID
福建 33
闽 33
广东 34
粤 34

select * from tableA where province in(select keyword where wordID=33
)
现在问题是我不想用in,我想用like的模糊查询.即只要出现过福建,闽的都找出来,那该怎么办呢?有没有什么高招!
...全文
36 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengdali 2003-10-29
  • 打赏
  • 举报
回复
province
----------------------------------------------------------------------------------------------------
sadfasf福建sadfas
sfasdfsa闽sdfass

(所影响的行数为 2 行)
pengdali 2003-10-29
  • 打赏
  • 举报
回复
编译错误??你试了没有呀


create table table_keyword(keyword varchar(10),wordID int)
insert table_keyword values('福建', 33 )
insert table_keyword values('闽' , 33)
insert table_keyword values('广东' , 34)
insert table_keyword values('粤' , 34 )

create table tableA (province varchar(100) )

insert tableA values('asdf大力asdf')
insert tableA values('sadfasf福建sadfas')
insert tableA values('sdfgdg广东sdfas')
insert tableA values('sfasdfsa闽sdfass')



select * from tableA tem where exists(select 1 from table_keyword where tem.province like '%'+keyword+'%' and wordID in (select wordid from table_keyword where keyword='福建'))



go
drop table table_keyword,tableA
gyx999 2003-10-29
  • 打赏
  • 举报
回复
wzh1215(四脚蛇)
table_keyword 中没有province字段啊
gyx999 2003-10-29
  • 打赏
  • 举报
回复
to pengdali(大力 V3.0)
编译不能通过,
select * from tableA tem where exists(select 1 from table_keyword where tem.province like '%'+keyword+'%' and wordID in (select wordid from table_keyword where keyword='福建'))

你的'%'+keyword+'%' 中的keyword是字段名吗?
wzh1215 2003-10-29
  • 打赏
  • 举报
回复
select * from tableA where province in(select keyword from table_keyword where province like '%'+keyword+'%')
wzh1215 2003-10-29
  • 打赏
  • 举报
回复
select * from tableA tem where wordID in (select wordID from table_keyword where province like '%'+keyword+'%')
pengdali 2003-10-29
  • 打赏
  • 举报
回复
或:

select * from tableA tem where exists(select 1 from table_keyword where charindex(keyword,tem.province)>0 and wordID=33)


charindex比like快
pengdali 2003-10-29
  • 打赏
  • 举报
回复
或:

select * from tableA tem where exists(select 1 from table_keyword where tem.province like '%'+keyword+'%' and wordID in (select wordid from table_keyword where keyword='福建'))
pengdali 2003-10-29
  • 打赏
  • 举报
回复
select * from tableA tem where exists(select 1 from table_keyword where tem.province like '%'+keyword+'%' and wordID=33)

34,874

社区成员

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

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