我试图弄清楚如何在 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