我正在使用MySQL和MySQL Workbench 5.2 CE。當我嘗試來連接2列,last_name
和first_name
,這是行不通的:MySQL中的字符串連接
select first_name + last_name as "Name" from test.student
我正在使用MySQL和MySQL Workbench 5.2 CE。當我嘗試來連接2列,last_name
和first_name
,這是行不通的:MySQL中的字符串連接
select first_name + last_name as "Name" from test.student
MySQL是大多數DBMS都使用的+
或||
進行連結不同。它採用CONCAT
功能:
SELECT CONCAT(first_name, " ", last_name) AS Name FROM test.student
由於@eggyal在評論中指出的那樣,你可以通過設置PIPES_AS_CONCAT
SQL模式實現與MySQL中||
操作字符串連接。
嘗試:
select concat(first_name,last_name) as "Name" from test.student
,或者更好:
select concat(first_name," ",last_name) as "Name" from test.student
使用concat()功能,而不是+
這樣的:
select concat(firstname, lastname) as "Name" from test.student
這不是在MySQL中Concat的方式。使用CONCAT功能看看這裏:http://dev.mysql.com/doc/refman/4.1/en/string-functions.html#function_concat
:)看你有多快得到答案! – Nishant
不能用+符號,是的,我得到了結果tho,謝謝所有:) – Roshan
@Nishant:只需3分鐘。 –