表book:
bookid
title 标题
content 内容
表titelkey
titelkey标题关键词
现在要将标题中含有任一标题关键词的bookid查询出来,该怎么写,谢谢~
------解决方案--------------------
- SQL code
goif OBJECT_ID('book')is not nulldrop table bookgocreate table book(bookid varchar(4),title varchar(20),content nvarchar(20))goinsert bookselect '1001','javaee',null union allselect '1002','sql server',null union allselect '1003','wp7',null union allselect '1004','android 2.3.4',null union allselect '1005','linux os',null union allselect '1006','android 2.3.0',null union allselect '1007','windows os',nullgoif OBJECT_ID('titelkey') is not nulldrop table titelkeygocreate table titelkey(tk varchar(10))goinsert titelkeyselect 'java' union allselect 'os' union allselect 'wp'select *,COUNT(1)over(partition by tk) as times--每个关键词有多少本相关bookfrom(select bookid,title,tk from bookcross join titelkeywhere CHARINDEX(tk,title)>0)t/*能看懂下面的结果吧bookid title tk times------------------------------1001 javaee java 11005 linux os os 21007 windows os os 21003 wp7 wp 1*/
------解决方案--------------------
全文索引查找。