Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在带有分隔符的MySQL字段上使用比较运算符的干净快捷的方法是什么?_Mysql_Sql_Operator Keyword_Delimiter - Fatal编程技术网

在带有分隔符的MySQL字段上使用比较运算符的干净快捷的方法是什么?

在带有分隔符的MySQL字段上使用比较运算符的干净快捷的方法是什么?,mysql,sql,operator-keyword,delimiter,Mysql,Sql,Operator Keyword,Delimiter,例如,字段由两个数据组成:基本级别和作业级别,并用分隔符分隔 字段名称:“baselvl:joblvl” 示例数据:“70:30”=>该条目表示基本级别为70,工作级别为30 我试图在PHP网站中包含一个搜索,以获取满足特定条件的数据。例如,获取基本级别为70或更高的数据。或者,比如说,基本水平大于50,工作水平小于或等于30 更新: 我忘了提到,他们设计这个字段时,joblvl部分是可选的 示例数据:“70'=>该条目表示基本级别为70,作业级别为0 是的,我同意,设计不是很好,但我不能改变它

例如,字段由两个数据组成:基本级别和作业级别,并用分隔符分隔

字段名称:“baselvl:joblvl”
示例数据:“70:30”=>该条目表示基本级别为70,工作级别为30

我试图在PHP网站中包含一个搜索,以获取满足特定条件的数据。例如,获取基本级别为70或更高的数据。或者,比如说,基本水平大于50,工作水平小于或等于30

更新: 我忘了提到,他们设计这个字段时,joblvl部分是可选的

示例数据:“70'=>该条目表示基本级别为70,作业级别为0

是的,我同意,设计不是很好,但我不能改变它。我必须了解它是怎样的

试试这个:

Declare @temp varchar(30)='70:40'
Declare @temp1 varchar(30)='70:10'


if (
convert(int,substring(@temp, 0,charindex(':',@temp)))>=convert(int,substring(@temp,
0,charindex(':',@temp1)))
and 
convert(int,substring(@temp,
charindex(':',@temp)+1,len(@temp)))>=convert(int,substring(@temp1,
charindex(':',@temp)+1,len(@temp1))))
  print 'yes'
我认为您正在使用mysql。使用以下查询拆分列

set @field='70:30';
select substr(@field,1,LOCATE(':',@field)-1) as baselvl,
substr(@field,LOCATE(':',@field)+1,length(@field)-LOCATE(':',@field)) as oblvl

请注意,最好的方法是将这两个值存储在单独的列中,否则您将来会遇到很多类似的问题

唯一“干净”的方法是重新设计表,将两个不同的属性存储在单独的列中。是的,mysql。如果我能改变它的存储方式,我会-但我不能。这很有效,谢谢!不幸的是,joblvl部分是可选的…=\例如,数据可以仅为“70”,以显示70个基本级别和0个作业级别。使用当前代码,它会将joblevel设置为70,将base level设置为0。有没有办法纠正这个问题?