且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在mysql中使用现有列名将两列合并成一列?

更新时间:2022-12-11 22:02:30

正如aziz-shaikh指出的,没有办法从 * 指令,但你可以使用下面的hack:

As aziz-shaikh has pointed out, there is no way to suppress an individual column from the * directive, however you might be able to use the following hack:

SELECT CONCAT(c.FIRSTNAME, ',', c.LASTNAME) AS FIRSTNAME,
       c.*
FROM   `customer` c;

这样做会导致第二次出现 FIRSTNAME 列采用别名 FIRSTNAME_1 ,因此您应该能够安全地处理您的自定义 FIRSTNAME 列。您需要对表进行别名,因为 * 在开头之外的任何位置都会失败,如果没有别名。

Doing this will cause the second occurrence of the FIRSTNAME column to adopt the alias FIRSTNAME_1 so you should be able to safely address your customised FIRSTNAME column. You need to alias the table because * in any position other than at the start will fail if not aliased.

希望有所帮助!