[英]Sql Query to transfer all records on another column on THE SAME table
Original Table Setup: 原始表格设置:
Table Name: property_details
Attribute: property_id, floor_area
Now, a new attribute is added named: total_area. 现在,添加了一个新属性,名为:total_area。
There are already records on property_details table with corresponding id and wanted to copy floor_area data to total_area . property_details表上已经存在具有相应ID的记录,并且想要将floor_area数据复制到total_area 。 (Will do something floor_area later)
(稍后将在floor_area做些事情)
For clarification, if this is in excel I will copy the value of A1 to B2 on the same row. 为了澄清起见,如果在excel中,我将在同一行中将A1的值复制到B2。 Pretty simple to demonstrate but can't figured out using sql.
演示很简单,但无法使用sql弄清楚。
Is this possible working on the same table? 这可以在同一张桌子上吗?
Just run an UPDATE
statement wherein the value of floor_area
is copied to total_area
, example, 只需运行
UPDATE
语句,其中将floor_area
的值复制到total_area
,例如,
UPDATE property_details
SET total_area= floor_area
更好的选择是将字段的名称从total_area更改为floor_area,这种情况下执行时间短且效率高,但是ID的ypur问题可能会更好,请先尝试采样或使用少量表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.