Mysql更新数据
更新
+-----+------------------+-------------+
| id | datenum | F1_baro_20_ |
+-----+------------------+-------------+
| 1 | 734152.000000000 | 1005.21 |
| 2 | 734152.006944445 | 1005.26 |
+-----+------------------+-------------+
这是我的表
这是我的新表
+-----+------------------+-------------+------------+
| id | datenum | F1_baro_20_ |new column |
+-----+------------------+-------------+------------+
| 1 | 734152.000000000 | 1005.21 | |
| 2 | 734152.006944445 | 1005.26 | |
+-----+------------------+-------------+------------+
我想将数据插入到“new_colum”,其中 old_datenum=new_datenum 但我不想修改现有数据!
UPDATE
+-----+------------------+-------------+
| id | datenum | F1_baro_20_ |
+-----+------------------+-------------+
| 1 | 734152.000000000 | 1005.21 |
| 2 | 734152.006944445 | 1005.26 |
+-----+------------------+-------------+
this is my table
And this is my new table
+-----+------------------+-------------+------------+
| id | datenum | F1_baro_20_ |new column |
+-----+------------------+-------------+------------+
| 1 | 734152.000000000 | 1005.21 | |
| 2 | 734152.006944445 | 1005.26 | |
+-----+------------------+-------------+------------+
I want to insert data to the 'new_colum' where old_datenum=new_datenum but I don't wan to modify the existing data!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个。
使用以下 SQL 查询添加一个新列:
其中
可以是 int、text、longtext、varchar(50) 之类的内容 - 具体取决于您的需要。然后使用这样的 SQL 查询仅更新此列:
或者如果您需要更新特定行(在列 id 为 2 的情况下选择):
这是将数据从 datenum 复制到 newColumn 的简单 SQL 查询:
运行该代码一次(但是当然还有你的表名和列名),你会看到数据被复制。
或者,如果您想使用 PHP 等来执行此操作:
这也会将所有数据从 datenum 复制到 newColumn。
Try this.
Add a new column with the following SQL query:
Where
<datatype>
can be something like int, text, longtext, varchar(50) - depending on what you need.Then update only this column with SQL queries like this:
or if you need to update a specific row (chosen where the column id is 2):
Here's the simple SQL query to copy the data from datenum to newColumn:
Run that code once (but with your table name and column name of course) and you'll see that the data is copied.
Or if you want to do it with, for example, PHP:
This will also copy all the data from datenum to newColumn.
Where 子句是可选的,如果您想向整个表添加相同的值,请忽略它。有关更多信息,请发布您的架构示例以及您想要的数据。
另请参见
http://dev.mysql.com/doc/refman/5.0 /en/update.html
The Where clause is optional, if you want to add the same value to the entire table ignore it. For more info post an example of your schema and what you want the data to be.
See also
http://dev.mysql.com/doc/refman/5.0/en/update.html
您可以简单地修改旧表来添加列。如果您不能这样做,那么只需在两个表上使用联接,如下所示
You can simply modify the old table to add the column.. If you cant do that, then just use a join on the two tables like this