fromtown 始发地区 totown目的地区 info 信息详情
南阳 咸阳 西安20-100吨
格尔木 金昌 西宁-金昌大量有焦炭
濮阳 南阳 2台前到南阳西峡 以上为数据库的一部分;我要查找, fromtown 为格尔木 并且totown为 金昌 还有 info 当中 包含 西宁与金昌等关键字的
数据,请个位帮帮 小弟!~
南阳 咸阳 西安20-100吨
格尔木 金昌 西宁-金昌大量有焦炭
濮阳 南阳 2台前到南阳西峡 以上为数据库的一部分;我要查找, fromtown 为格尔木 并且totown为 金昌 还有 info 当中 包含 西宁与金昌等关键字的
数据,请个位帮帮 小弟!~
解决方案 »
- MYSQL如何连接字符,并 exec sp_executesql 拼接的字符串
- MySql与GSM无线通信的问题
- 问一个联表赋值的问题
- delete from password n where n.user_id in(select n.user_id from password n where n.uid='3584');
- mysql5中的information_schema数据库
- 关于时间的查询问题!?
- MySql5.0 Alpha版是不是最新版,稳定性如何?
- 连不上本机的mysql数据库!!!(急、解决马上给分!!!)
- mysql5.6重启 停止 开始服务的问题
- mysql远程连接如何开启
- 一个表内的某个字段是vachar型,内容可能是gb2312,也可能是big5,怎么办才能避免乱码?
- 谈谈SUN被Oracle收购后 My SQL的出路何在呢?
select * from tt where fromtown='格尔木' and totown='金昌' and
(instr(info,'西宁')>0 or instr(info,'金昌')>0 )
你的下边这样
就不对了,应该吧 西宁与金昌和起来,其中用逗号隔开就行了。本人很菜,希望大哥能给解答 !~
估计你要用正则表达式
所有包含 a 中任何一个或者多个的 数据的查询!~~
from yourTable
where fromtown='格尔木'
and totown='金昌'
and info like '%西宁%'
and info like '%金昌%'
select *
from yourTable
where fromtown='格尔木' -- fromtown 为格尔木
and totown='金昌' -- 并且totown为 金昌
and info like '%西宁%' -- 还有 info 当中 包含 西宁
and info like '%金昌%' -- 与金昌
结果要求1:查找 含有关键字中一个关键字 (金昌或者西宁或者xx或者xx的信息) ! ~~这是一种情况
2: 查找 含有所有关键字的(金昌,西宁,xx,xx 全部包含)信息!~~这是第二种
结果要求1:查找 含有关键字中一个关键字 (金昌或者西宁或者xx或者xx的信息) ! ~~这是一种情况
2: 查找 含有所有关键字的(金昌,西宁,xx,xx 全部包含)信息!~~这是第二种
1、
select *
from yourTable
where fromtown='格尔木'
and totown='金昌'
and info regexp replace('金昌,西宁,xx,xx',',','|' )2、
准确匹配select *
from yourTable
where fromtown='格尔木'
and totown='金昌'
and concat(',',info,',') regexp
concat(',',replace('金昌,西宁,xx,xx',',','|' ),',')两种在一条SQL语句select *
from yourTable
where fromtown='格尔木'
and totown='金昌'
AND
(concat(',',info,',') regexp
concat(',',replace('金昌,西宁,xx,xx',',','|' ),',')
OR
info regexp replace('金昌,西宁,xx,xx',',','|' )
)