搞清楚如何做sql列别名

时间:2015-04-17 15:43:20

标签: mysql database

我一直试图弄清楚如何使用此查询执行列别名,但我似乎无法得到它。

SELECT (customer.customer_id) as ID, (CUSTOMER.FIRST_NAME, CUSTOMER.LAST_NAME) as name, (customer.address,customer.town,customer.post_code) as address, LOYALTY_CARD.POINTS 
FROM LOYALTY_CARD 
INNER JOIN CUSTOMER 
ON LOYALTY_CARD.CUSTOMER_ID = CUSTOMER.CUSTOMER_ID WHERE LOYALTY_CARD.POINTS > 70 ORDER BY LOYALTY_CARD.POINTS

我收到的错误是operand should contain 1 column

1 个答案:

答案 0 :(得分:1)

(CUSTOMER.FIRST_NAME, CUSTOMER.LAST_NAME) as name错了。如果你想要将它们组合起来,你需要将它们连接起来。

concat(customer.first_name, ' ', customer.last_name) as name

(customer.address,customer.town,customer.post_code) as address

相同

concat(customer.address, ' ', customer.town, ' ', customer.post_code) as address