select count(*) from Huo_v  where Area in ('北京','郑州','济南','枣庄','沈阳') and (Keywords like '%扬州%' or Keywords like '%泰州%' or Keywords like '%淮安%' or Keywords like '%宿迁%' or Keywords like '%盐城%' or Keywords like '%南通%' or Keywords like '%南京%' or Keywords like '%徐州%' or Keywords like '%连云港%' or Keywords like '%镇江%' or Keywords like '%常州%' or Keywords like '%无锡%' ) 

解决方案 »

  1.   

    area,keywords已经同时设置为了索引,id是主索引 
      

  2.   

    CREATE TABLE [dbo].[Huo_v] (
    [ID] [int] IDENTITY (1, 1) NOT NULL ,
    [Class] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
    [Sender] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL ,
    [AddTime] [datetime] NOT NULL ,
    [Body] [varchar] (500) COLLATE Chinese_PRC_CI_AS NOT NULL ,
    [Area] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ,
    [Status] [bit] NULL ,
    [Keywords] [varchar] (500) COLLATE Chinese_PRC_CI_AS NULL 
    ) ON [PRIMARY]
    Huo_v表结构
      

  3.   

    Keywords这个地方可能要like到30个城市,城市多了速度就慢了,有什么办法能在一秒到二秒之间解决?
      

  4.   

    and (Keywords like '%扬州%' or Keywords like '%泰州%' or Keywords like '%淮安%' or Keywords like '%宿迁%' or Keywords like '%盐城%' or Keywords like '%南通%' or Keywords like '%南京%' or Keywords like '%徐州%' or Keywords like '%连云港%' or Keywords like '%镇江%' or Keywords like '%常州%' or Keywords like '%无锡%' ) 这么多的like运算,很难了。
      

  5.   

    你的keywords如果只是城市的话,你看看这个的速度是多少后面的like换成这个 charindex(keywords ,'扬州泰州淮安宿迁盐城南通南京徐州连云港镇江常州无锡' ) 
    估计也达不到你的要求
      

  6.   

    我的keywords里面格式是这样的  淮安,宿迁,盐城,南通
      

  7.   

    如果按照你的方法,就要用到很多个charindex
      

  8.   

    charindex(keywords ,'扬州,泰州,淮安,宿迁,盐城,南通,南京,徐州,连云港,镇江,常州,无锡' ) >0需要多长时间?
      

  9.   

    charindex(keywords ,'扬州,泰州,淮安,宿迁,盐城,南通,南京,徐州,连云港,镇江,常州,无锡' ) >0 
    keywords 是这个全国城市的任意组合,个数不定,如(连云港,徐州,郑州)
      

  10.   

    我觉得应该尽可能在拼 SQL 前解决掉
      

  11.   

    我觉得应该尽可能在拼 SQL 前解决掉?这个详细点!
      

  12.   

    --如果Area上是聚集索引的话:select 1 from Huo_v  where Area='北京' and ...
    union all
    select 1 from Huo_v  where Area='郑州' and ...
    union all
    select 1 from Huo_v  where Area='济南' and ...
    union all
    select 1 from Huo_v  where Area='枣庄' and ...
    union all
    select 1 from Huo_v  where Area='沈阳' and ...select @@rowcount