关于同一个字段的多条件模糊查询

lsmini 2012-09-07 03:07:23
现在碰到一个问题:我有一个字段是url
里面相应的数据有很多:比如/home/,/home/corner_one/,/home/js,/home/corner_one/......
现在我想查询/home/和/home/corner的结果。
INSERT INTO mytable
select Address,Time,[Referrer URL] from test2.dbo.['status 200$']
where [Referrer URL] like ‘/home/’and '%/home/c%'
但是显示结果不对。

请问应该如何写呢?

谢谢啦!
...全文
662 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
以学习为目的 2012-09-08
  • 打赏
  • 举报
回复
; with cte
as
(
select Address,Time,[Referrer URL]
from test2.dbo.['status 200$']
where charindex(['/home/',Referrer URL]>0 or charindex('/home/corner',Referrer URL)>0
)a
insert into mytable select * from cte
發糞塗牆 2012-09-07
  • 打赏
  • 举报
回复
想楼主这种数据,我认为,使用正则表达式或者全文检索,可能效率会更高。
yy1987316 2012-09-07
  • 打赏
  • 举报
回复
or连接两个条件。

INSERT INTO mytable
select Address,Time,[Referrer URL] from test2.dbo.['status 200$']
where [Referrer URL]='/home/'or [Referrer URL]='/home/corner'


[Quote=引用 3 楼 的回复:]

INSERT INTO mytable
select Address,Time,[Referrer URL] from test2.dbo.['status 200$']
where [Referrer URL] ='/home/'or '/home/c%'

这是我写的代码。
错误:
訊息 4145,層級 15,狀態 1,行 3
在有預期條件的內容中指定的非布林類型……
[/Quote]
lsmini 2012-09-07
  • 打赏
  • 举报
回复
INSERT INTO mytable
select Address,Time,[Referrer URL] from test2.dbo.['status 200$']
where [Referrer URL] ='/home/'or '/home/c%'

这是我写的代码。
错误:
訊息 4145,層級 15,狀態 1,行 3
在有預期條件的內容中指定的非布林類型運算式,接近 '/home/c%'。
  • 打赏
  • 举报
回复

INSERT INTO mytable select Address,Time,[Referrer URL] from test2.dbo.['status 200$'] where [Referrer URL]='/home/'
or [Referrer URL] like '/home/c%'
koumingjie 2012-09-07
  • 打赏
  • 举报
回复
INSERT INTO mytable
select Address,Time,[Referrer URL] from test2.dbo.['status 200$']
where [Referrer URL] ='/home/' or '/home/corner'

34,838

社区成员

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

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