在线急等,求一段匹配查询执行效率搞的sql语句

vgy12304 2009-06-19 02:35:09
条件表userinto
编号 名称
id title
1 快餐
2 婚宴
3 聚会
4 生日宴
5 自助餐
...
11 火锅
12 牛排


要查询的表Hotellist
--------------------------
编号 名称 用途id(多个文本)
id title userintoid
1 "餐厅1" "1,3,5"
2 "餐厅2" "1,2,3"
3 "餐厅3" "1,10,12"
...
56 "餐厅56" "1,11,12"



查询表Hotellist的记录
比如我要查询用途id是婚宴的(即 userintoid 中包含 2 还不是12的),那么我的查询语句怎么写

select title from Hotellist where userintoid like ???
...全文
36 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
vgy12304 2009-06-19
  • 打赏
  • 举报
回复
好了,问题解决,谢谢2楼的提供灵感,50给你了
vgy12304 2009-06-19
  • 打赏
  • 举报
回复
顶上来access不支持charindex吧
我在网上找的这个
select * from Hotellist where yanhui=1 and InStr(useintoid,'3')>0 order by signed desc , num asc , clieck desc , id desc


得到的结果不对,只有1条符合条件的正常,超过2条,只读出两条记录
vgy12304 2009-06-19
  • 打赏
  • 举报
回复
回2楼,
我是access的,支持这个语法吗

我的语句执行超时了,120秒都没执行完,这个效率也太汗了
smartcatiboy 2009-06-19
  • 打赏
  • 举报
回复
数据库违反1NF了,应该这样设计Hotelist


create table tblHotelist(strTitle,userintoid,pk(strTitle,userintoid))

title userintoid
"餐厅1" 1
"餐厅1" 3
"餐厅1" 5
"餐厅2" 1
"餐厅2" 2
"餐厅2" 3
"餐厅3" 1
"餐厅3" 10
"餐厅3" 2

查寻的时候用
select title from tblHotelist where userintoid=1 group by title
列表的时候用transform
shenzhenNBA 2009-06-19
  • 打赏
  • 举报
回复
SQL SERVER 的如下:

select [title] from Hotellist where charindex('2',[userintoid])>0

指定的ID好根据自己需要修改即可,呵呵。。。刚才有个顺序弄反了,修改见红色部分
shenzhenNBA 2009-06-19
  • 打赏
  • 举报
回复
SQL SERVER 的如下:

select [title] from Hotellist where charindex([userintoid],'2')>0

指定的ID好根据自己需要修改即可

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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