[英]Combining created columns in MySQL
I have a MySQL query which returns columns from different tables, as well as a column that I've customized personally through a case statement. 我有一个MySQL查询,该查询返回不同表中的列,以及我通过case语句个人定制的列。
SELECT table.column,
CASE (...) as new_column
The thing is, I want to concatenate table.column
and new_column
in this query, although I can't independently call new_column
since I created it in the query. 事实是,我想在此查询中连接
table.column
和new_column
,尽管自从我在查询中创建它以来就无法独立调用new_column
。
Due to database privileges, I can't actually create tables on the database. 由于数据库特权,我实际上无法在数据库上创建表。
Thoughts on how I should approach this? 关于我应该如何处理的想法?
You can just wrap that whole select into a CONCAT()
function: 您可以将整个选择包装到
CONCAT()
函数中:
SELECT CONCAT(table.column, CASE(...)) AS new_column
FROM table;
Another way of approaching it, not that I recommend it but it may be a little more readable, is to use your current query as a subquery and concatenate from the parent one: 解决该问题的另一种方法(不是我推荐的,但可能更具可读性)是将当前查询用作子查询并与父查询连接:
SELECT CONCAT(column, new_column) AS new_column
FROM(
SELECT table.column, CASE(...) AS new_column
FROM table
) tmp;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.