Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.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/5/sql/78.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 - Fatal编程技术网

Mysql 喜欢和作为文本结果

Mysql 喜欢和作为文本结果,mysql,sql,Mysql,Sql,我试图找出如何在MySQL中运行查询,该查询将执行以下操作: 搜索任何以5开头的数字,并在标有classRef的列中显示结果,结果文本为FOO 如果该数字以5以外的任何数字开头,则将其输出到classRef列,结果文本为BAR 这就是我到目前为止所做的: SELECT ara.AddressNumber AS ExternalID, ara.AddressNumber as tranId, cus.Name AS customerRef, cus.ExternalID LIKE '5%' AS

我试图找出如何在MySQL中运行查询,该查询将执行以下操作:

  • 搜索任何以5开头的数字,并在标有classRef的列中显示结果,结果文本为FOO
  • 如果该数字以5以外的任何数字开头,则将其输出到classRef列,结果文本为BAR 这就是我到目前为止所做的:

    SELECT
    ara.AddressNumber AS ExternalID,
    ara.AddressNumber as tranId,
    cus.Name AS customerRef,
    cus.ExternalID LIKE '5%' AS classRef,
    cus.ExternalID NOT LIKE '5%' AS classRef2,
    '1' AS itemLine_quantity,
    '0' AS itemLine_salesPrice
    
    FROM
    adrun_copy ara,
    customers_copy cus
    
    WHERE
    ara.AAccountNumber = cus.ExternalID
    
    如果这真的是一个像
    int
    这样的数字列,那么您可能需要
    首先将其转换为varchar。。。我不确定MySql的规则

    CASE WHEN cus.ExternalID LIKE '5%' THEN 'FOO' ELSE 'BAR' END As classRef