我从客户端继承了一个简单的表,它只在两个字段shipping_address和business_address中存储了两个地址(送货地址和商家地址)。有一个名为ship_to的字段,包含enum('shipping','business')和一个全名字段。客户希望输出为:
全名:地址
其中“address”列应由ship_to值选取。如果ship_to = shipping,则使用shipping_address列。如果ship_to = business,则使用business_address列。
例如:
Joe Smith: Roach Street #10, Rats Village
如何在IF情况下使用CONCAT?我猜测这样的东西,这显然只是一个想法:
SELECT CONCAT( full_name, ':', IF (ship_to=='shipping', shipping_address, business_address ) AS contact FROM `table`
但是,这样做的正确语法是什么?
答案 0 :(得分:2)
缺少结束)
SELECT
CONCAT( full_name, ':', IF (ship_to='shipping', shipping_address, business_address )) as contact
FROM TableName