呵呵,如果是我,我会建两张表,第一张表为存放城市,字段(ID,CITY),第二张表存放企业名称(CITY_ID,NAME),两张表都建好索引,其中第一张表ID为主键,第二张表CITY_ID,NAME为主键 , SQL语句= select 查询的城市名 as city,name from 企业名称表 where city_id in (select id from 城市表 where city='查询的城市名') and name like '%查询的企业名片段%';如果当前就一张表不变的情况下 企业表结构 Name 企业名称 city 城市 设Name、city为主键,并建索引, SQL语句=select city,name from 企业表结构 where city='查询的城市名' and name like '%查询的企业名片段%'
如果当前就一张表不变的情况下 企业表结构 Name企业名称 city城市 设Name、city为主键,并建索引, SQL语句=select city,name from 企业表结构 where city='查询的城市名' and name like '%查询的企业名片段%'这样建索引完全无效!可以用嵌套查询或临时表
嵌套查询select city,name from(select city,name from 企业表 where city=输入的城市) where name like %xxx%第一次查询,可以让数据表里面的1千万条数据剩下很少.然后在这查询结果下再来模糊查询. 如果翻页的话.用存储过程传入翻页参数以及每页要显示的条数,通过这样来翻页.这样的思路不知对不对,请楼下指点
在name上建一个索引(idx_name), 在city上建一个索引(idx_city), sql如下: select/*+index(idx_city,企业表)*/ name,city from ( select/*+index(idx_name,企业表)*/ name,city from 企业表 where name like '%企业名称%') where city = 城市
有人说不用like 语法。用instr()函数也可以。 但是不知道哪个效率高。
在name上建一个索引(idx_name), 在city上建一个索引(idx_city), sql如下: select/*+index(企业表,idx_city)*/ name,city from ( select/*+index(企业表,idx_name)*/ name,city from 企业表 where name like '%企业名称%') where city = 城市 更正。。很久没写了。语法都忘了。失败!!!!
刚才没有看到要分页。 在补充。。呵呵。。在name上建一个索引(idx_name), 在city上建一个索引(idx_city), sql如下: select name,city from( select/*+index(企业表,idx_city)*/ name,city from ( select/*+index(企业表,idx_name)*/ name,city from 企业表 where name like '%企业名称%') where city = 城市 ) where rownum > (i-1)*10 and rownum <i*10i表示当前页(每页10条数据)。根据用户选择传进来。这样不用每次都把所有数据查出来。
刚才没有看到要分页。 在补充。。呵呵。。在name上建一个索引(idx_name), 在city上建一个索引(idx_city), sql如下: select name,city from( select/*+index(企业表,idx_city)*/ name,city from ( select/*+index(企业表,idx_name)*/ name,city from 企业表 where name like '%企业名称%') where city = 城市 ) where rownum > (i-1)*10 and rownum <=i*10 呵呵。。补充。要不每页会掉了一条数据
,
SQL语句=
select 查询的城市名 as city,name from 企业名称表 where city_id in (select id from 城市表 where city='查询的城市名') and name like '%查询的企业名片段%';如果当前就一张表不变的情况下
企业表结构
Name 企业名称
city 城市
设Name、city为主键,并建索引,
SQL语句=select city,name from 企业表结构 where city='查询的城市名' and name like '%查询的企业名片段%'
一楼的做法应该是有问题的
继续关注一下吧
不用like,而用contains,对企业那个字段建立全文索引,这样速度会快非常多不过他没说明是什么数据库,要那么高性能的分页不是容易事,或者要看城市数据和企业数据分布的均匀程度
企业表结构
Name企业名称
city城市
设Name、city为主键,并建索引,
SQL语句=select city,name from 企业表结构 where city='查询的城市名' and name like '%查询的企业名片段%'这样建索引完全无效!可以用嵌套查询或临时表
like '%xxx' 是不可以使用索引的
like '%xxx%' 也是不可以使用索引的
where name like %xxx%第一次查询,可以让数据表里面的1千万条数据剩下很少.然后在这查询结果下再来模糊查询.
如果翻页的话.用存储过程传入翻页参数以及每页要显示的条数,通过这样来翻页.这样的思路不知对不对,请楼下指点
在name上建一个索引(idx_name),
在city上建一个索引(idx_city),
sql如下:
select/*+index(idx_city,企业表)*/ name,city
from ( select/*+index(idx_name,企业表)*/ name,city
from 企业表
where name like '%企业名称%')
where city = 城市
但是不知道哪个效率高。
在city上建一个索引(idx_city),
sql如下:
select/*+index(企业表,idx_city)*/ name,city
from ( select/*+index(企业表,idx_name)*/ name,city
from 企业表
where name like '%企业名称%')
where city = 城市
更正。。很久没写了。语法都忘了。失败!!!!
在补充。。呵呵。。在name上建一个索引(idx_name),
在city上建一个索引(idx_city),
sql如下:
select name,city
from(
select/*+index(企业表,idx_city)*/ name,city
from ( select/*+index(企业表,idx_name)*/ name,city
from 企业表
where name like '%企业名称%')
where city = 城市
)
where rownum > (i-1)*10
and rownum <i*10i表示当前页(每页10条数据)。根据用户选择传进来。这样不用每次都把所有数据查出来。
在补充。。呵呵。。在name上建一个索引(idx_name),
在city上建一个索引(idx_city),
sql如下:
select name,city
from(
select/*+index(企业表,idx_city)*/ name,city
from ( select/*+index(企业表,idx_name)*/ name,city
from 企业表
where name like '%企业名称%')
where city = 城市
)
where rownum > (i-1)*10
and rownum <=i*10
呵呵。。补充。要不每页会掉了一条数据