我有一个表称为Records
具有数据作为以下各项如何在同一个表中的Postgres插入相同的数据(或复制)为不同的记录
Section_one | section_two | values | cDate
name_Fit | hellp0 | present | 2014-08-23
name_Fit | onew | parcel | 2014-08-21
name_Fit | twow | new thing | 2014-07-04
现在我想插入一个名为新数据name_Fit_one
与第section_one
列相对应,其应该具有与其相对应的类似数据(列section_two
和values
)。
我试图写的SQL来做到这一点,但我得到的postgres错误。任何人都可以请纠正我我做错了什么?
Insert into records(section_one,section_two,values) Values ('name_Fit_one', select section_two,values from records where section_one='name_Fit');
预期结果
Section_one | section_two | values | cDate
name_Fit | hellp0 | present | 2014-08-23
name_Fit | onew | parcel | 2014-08-21
name_Fit | twow | new thing | 2014-07-04
name_Fit_one| hellp0 | present | 2014-08-29
name_Fit_one| onew | parcel | 2014-08-29
name_Fit_one| twow | new thing | 2014-08-29
需要编写一个将记录的内容复制到另一个记录单查询?
下面是它 -
http://sqlfiddle.com/#!2/9de58/1
你的标签说postgresql,但你的sqlfiddle是mysql。你真的在用什么数据库?你的数据也显示一列“值”,但你的小提琴显示“价值”,这是正确的?也是cdate时间戳字段(如在你的小提琴)或日期字段(如上面的数据)? – 2014-08-29 21:59:54