Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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_Regex - Fatal编程技术网

MySQL如果是数字,请选择其他列

MySQL如果是数字,请选择其他列,mysql,regex,Mysql,Regex,是否有mysql函数检查值是否仅为数字 我不想在两个柱子上, 如果tbl3.column2是数字,则使用其他表格列进行连接;如果是字符串,则使用相同的表格其他列进行连接 SELECT tbl1.column1 as Column1, tbl2.column2 as Column2, IF tbl3.column2 REGEXP '^[0-9]+$' THEN CONCAT(tbl3.column1, ' ', tbl4.column1) ELSE CONCAT(tbl3.column1, '

是否有mysql函数检查值是否仅为数字

我不想在两个柱子上, 如果tbl3.column2是数字,则使用其他表格列进行连接;如果是字符串,则使用相同的表格其他列进行连接

SELECT tbl1.column1 as Column1, tbl2.column2 as Column2, 
IF tbl3.column2 REGEXP '^[0-9]+$' THEN CONCAT(tbl3.column1, ' ', tbl4.column1) ELSE CONCAT(tbl3.column1, ' ', tbl3.column2) END IF as Combined
FROM table1 tbl1
LEFT JOIN table2 tbl2 ON tbl1.id = tbl2.id
LEFT JOIN table3 tbl3 ON tbl3.id = tbl1.id
LEFT JOIN table4 tbl4 ON tbl4.id = tbl1.id
LEFT JOIN table5 tbl5 ON tbl5.id = tbl1.id 
WHERE
tbl5.column3 = ?
ORDER BY Column1 ASC
当前代码给出错误:

You have an error in your SQL syntax; check the manual that corresponds
 to your MySQL server version for the right syntax to use near 'tbl3.column2 REGEXP '^[0-9]+$'
    THEN CONCAT(tbl3.column1, ' ', tbl4.column1' at line
请试试这个:

SELECT tbl1.column1 AS Column1, tbl2.column2 AS Column2, 
IF(tbl3.column2 REGEXP '^[0-9]+$'
    , CONCAT(tbl3.column1, ' ', tbl4.column1)
    , CONCAT(tbl3.column1, ' ', tbl3.column2)
    ) AS Combined
FROM table1 tbl1
LEFT JOIN table2 tbl2 ON tbl1.id = tbl2.id
LEFT JOIN table3 tbl3 ON tbl3.id = tbl1.id
LEFT JOIN table4 tbl4 ON tbl4.id = tbl1.id
LEFT JOIN table5 tbl5 ON tbl5.id = tbl1.id 
WHERE
tbl5.column3 = ?
ORDER BY Column1 ASC
请试试这个:

SELECT tbl1.column1 AS Column1, tbl2.column2 AS Column2, 
IF(tbl3.column2 REGEXP '^[0-9]+$'
    , CONCAT(tbl3.column1, ' ', tbl4.column1)
    , CONCAT(tbl3.column1, ' ', tbl3.column2)
    ) AS Combined
FROM table1 tbl1
LEFT JOIN table2 tbl2 ON tbl1.id = tbl2.id
LEFT JOIN table3 tbl3 ON tbl3.id = tbl1.id
LEFT JOIN table4 tbl4 ON tbl4.id = tbl1.id
LEFT JOIN table5 tbl5 ON tbl5.id = tbl1.id 
WHERE
tbl5.column3 = ?
ORDER BY Column1 ASC

这个问题似乎是设计不好的症状是只是表名足以做出判断@Strawberry这个问题似乎是设计不好的症状是只是表名足以做出判断@Strawberry