简体   繁体   English

如何在不列出其他现有列的情况下将新列添加到MySQL表

[英]How to add new column to MySQL table without listing other existing columns

Say that we have a mysql table that has 100 columns. 假设我们有一个包含100列的mysql表。 Now, I know that if we wanted to have a new column that has the sum of the values of two columns we could use the SUM function on the two columns after SELECT , but then I also have to list the names of the other 100 columns. 现在,我知道,如果我们要创建一个包含两列值之和的新列,我们可以在SELECT之后在两列上使用SUM函数,但是我还必须列出其他100列的名称。 Is there a way to have a table that has the 100 columns plus the SUM function without listing those columns after SELECT . 有没有一种方法可以使表具有100列以及SUM函数,而不必在SELECT之后列出这些列。

SELECT c1+c2, c1, c2, c3, c4,...,c100 FROM columns

您可以只使用通配符( * ):

SELECT *, c1 + c2 AS sum FROM columns

尝试:

SELECT c1+c2, t.* FROM columns t

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

相关问题 如何将n个列添加到现有表中,新列应具有现有列的聚合 - How to add n number of columns to an existing table,the new columns should have the aggregate of an existing column 如何在Laravel中向现有表添加新列 - How to add new column to existing table in laravel MYSQL如何将虚拟列添加到现有表中 - MYSQL How to add virtual column into existing table 如何在从 mysql 中的现有表创建表时添加新的日期列 - how to add new date column while creating table from existing table in mysql 向现有表添加新列并将其显示到视图刀片中(LARAVEL、mysql) - add new column to existing table and show it into a view blade (LARAVEL,mysql) 将带有聚合查询的新列添加到mysql中的现有表中 - Add a new column with aggregate query into an existing table in mysql CakePHP的新功能->如何向MySQL表添加列? - New to CakePHP -> How To Add Columns To a MySQL Table? 如何在没有主键的情况下将数据作为新列插入MySQL中的现有表? - How to insert data as new column without primary keys to existing table in MySQL? 将新列添加到表中并填充其他2列的数据? - Add new column to table and fill with the data of 2 other columns? 如何将新条目添加到 mysql 表中,但仅适用于 1 列,同时保留所有其他列数据 - How can i add a new entry into a mysql table, BUT only for 1 column, while keeping all other column data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM