求一个高效的查询语句

众联财务 2009-04-08 01:06:10
现在的:
select * from nfwlw where bs in('赣州','吉安','龙岩','梅州','三明','抚州') or describe1 like '%赣州%' or describe1 like '%梅州%' or describe1 like '%龙岩%' or describe1 like '%吉安%' or describe1 like '%泰和%' or describe1 like '%遂川%' or describe1 like '%三明%' or describe1 like '%鹰潭%' or describe1 like '%上饶%' order by ID DESC

大约10万数据,现在查询好慢
...全文
126 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zdzcool 2009-04-08
  • 打赏
  • 举报
回复
up
taoistong 2009-04-08
  • 打赏
  • 举报
回复
楼上的一样,
不要用like '%龙岩%'
用 like '龙岩%'

在此列创建索引,效率会高点,
yuyangyangde 2009-04-08
  • 打赏
  • 举报
回复

select * from nfwlw where bs in('赣州','吉安','龙岩','梅州','三明','抚州') order by ID DESC
union all
select * from bs where describe1 like '%赣州%' order by ID DESC
union all
select * from bs where describe1 like '%梅州%' order by ID DESC
union all
select * from bs where describe1 like '%龙岩%' order by ID DESC
union all
select * from bs where describe1 like '%吉安%' order by ID DESC
union all
select * from bs where describe1 like '%泰和%' order by ID DESC
union all
select * from bs where describe1 like '%遂川%' order by ID DESC
union all
select * from bs where describe1 like '%三明%' order by ID DESC
union all
select * from bs where describe1 like '%鹰潭%' order by ID DESC
union all
select * from bs where describe1 like '%上饶%' order by ID DESC

众联财务 2009-04-08
  • 打赏
  • 举报
回复
describe1是一句话。不是单独的城市名
jinjazz 2009-04-08
  • 打赏
  • 举报
回复
describe1 的字段设计有问题,既然是城市这么明显的信息,为什么不单独设定字段加索引 用等于,就不会慢了

34,593

社区成员

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

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