Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/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 - Fatal编程技术网

根据子字符串比较设置MySQL字段

根据子字符串比较设置MySQL字段,mysql,Mysql,我正在从MySQL服务器提取数据,在几种情况下,我使用onquery替换。在示例中,如果我有一个空字段,它将为某些字段分配一个空字符串,如: ifnull(`negotiation_type`, "") AS negotiation_type 现在我需要做类似的测试,但是使用子字符串。我有一个url字段,我想根据它的值设置另一个字段值,称为property\u type 所有URL都将具有子字符串house或partment,如: http://www.example.com/?pics=tr

我正在从MySQL服务器提取数据,在几种情况下,我使用onquery替换。在示例中,如果我有一个空字段,它将为某些字段分配一个空字符串,如:

ifnull(`negotiation_type`, "") AS negotiation_type
现在我需要做类似的测试,但是使用子字符串。我有一个url字段,我想根据它的值设置另一个字段值,称为property\u type

所有URL都将具有子字符串housepartment,如:

http://www.example.com/?pics=true/tree-house-over-the-tree
http://www.example.com/?pics=true/blue-apartment-under-the-tere
我想知道,如果将LOCATE函数与任何其他mySQL函数组合,我是否能够在SELECT上进行属性类型的赋值

有人有主意吗


谢谢

我想这一个就可以了:

SELECT IF(LOCATE('HOUSE', `url`) > 0, 'HOUSE',IF( 
LOCATE('APPARTEMENT', `url`) > 0, 'APPARTEMENT', 'OTHER')) AS property_type 

完美的这就是我需要的。。非常感谢。