MySQL - 选择CONCAT AS''& ORDER BY - 错误/不工作?

时间:2014-05-06 13:49:04

标签: mysql sql

我要做的是输出(order_id,payment_type)以及' Order&amp ;;使用的付款方式'和(order_date,order_time)以及'日期/时间'的列标题。我现在以多种不同的方式尝试了以下查询,但我总是遇到错误。

查询我正在尝试执行

SELECT CONCAT('order_id', ' ', 'payment_type') AS 'Order & Payment Type Used', 
       CONCAT('order_date', ' ', 'order_time') AS 'Date/Time' 
  FROM 'ORDER' 
       ORDER BY order_id;  

错误结果

#1064 - 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 ''ORDER' ORDER BY
order_id LIMIT 0, 30' at line 1 

表。 。 。 的' ORDER'

order_id
order_date
order_time
payment_type

3 个答案:

答案 0 :(得分:1)

使用'

取消特殊名称
SELECT CONCAT(`order_id`, ' ', `payment_type`) AS `Order & Payment Type Used`,
  CONCAT(`order_date`, ' ', `order_time`) AS `Date/Time`
FROM `ORDER` ORDER BY order_id;  

'用于字符串。

答案 1 :(得分:1)

对列和表名使用反向标记,对于字符串和日期使用引号

`order_id`, ' ', `payment_type`

答案 2 :(得分:0)

如果您的列名包含任何空格或任何特殊字符,那么您必须使用返回刻度,否则您可以保留列名称,或者您也可以使用返回刻度,但不能在引号下包含列名称作为mysql处理它作为恒定值。您可以使用以下查询。

SELECT 
CONCAT(order_id, ' ', payment_type) AS 'Order & Payment Type Used', 
CONCAT(order_date, ' ', order_time) AS 'Date/Time' 
FROM `ORDER` 
ORDER BY order_id;