fromtown 始发地区 totown目的地区 info 信息详情
南阳 咸阳 西安20-100吨
格尔木 金昌 西宁-金昌大量有焦炭
濮阳 南阳 2台前到南阳西峡 以上为数据库的一部分;我要查找, fromtown 为格尔木 并且totown为 金昌 还有 info 当中 包含 西宁与金昌等关键字的
数据,请个位帮帮 小弟!~
南阳 咸阳 西安20-100吨
格尔木 金昌 西宁-金昌大量有焦炭
濮阳 南阳 2台前到南阳西峡 以上为数据库的一部分;我要查找, fromtown 为格尔木 并且totown为 金昌 还有 info 当中 包含 西宁与金昌等关键字的
数据,请个位帮帮 小弟!~
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',',','|' )
)