简体   繁体   English

在选择中添加带有“ *”的额外列

[英]Add an extra column in select with '*'

I am writing a query sql for a data migration job to fetch data and send from mysql-server a to mysql-server b. 我正在为数据迁移作业编写查询sql,以获取数据并将其从mysql-server a发送到mysql-server b。

Server a has different databases, representing different game channel, and each database has a table tablex , they have same table name and same schema: 服务器a具有不同的数据库,代表不同的游戏频道,并且每个数据库都有一个表tablex ,它们具有相同的表名和相同的架构:

 uid  level
 123    3
 211    5

While in server b there is only one table tablex to receive tablex of all databases and it has one more column - channel 在服务器b中,只有一个表tablex可以接收所有数据库的tablex,并且它还有一个列- channel

channel uid  level
 1      123    3
 1      211    5
 2      355    2

I can parse channel number from db name via python but I need to put this constant in the sql and since there are many tables, I cannot fix the columns. 我可以通过python从数据库名称中解析通道号,但是我需要将此常量放在sql中,并且由于有很多表,因此无法修复列。 So just want to make sure is there any way to do this like: 因此,只需确保有任何方法可以做到这一点:

select 1,* from xxx.yyy

You could try adding alias and table name 您可以尝试添加别名和表名

select 1 as my_col, yyy.* from xxx.yyy

or using string 或使用字符串

select cast('1'  as  unsigned) , yyy.* from xxx.yyy

Yes, you can wrap the query into another SELECT and add the columns, eg: 是的,您可以将查询包装到另一个SELECT并添加列,例如:

SELECT A.*, '1'
FROM (
  SELECT *
  FROM your_table
) A;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM