我正在尝试编写一个复制所有行WHERE employee = 16
(即。)的SQL语句,但新行的值会有不同的employee
。
INSERT
之前的表格:
| employee | property_name | property_value |
|:--------:|:--------------|:---------------|
| 16 | Salary | 28,000 |
| 16 | Department | 12 |
| 17 | Salary | 38,000 |
| 17 | Department | 8 |
INSERT
之后的期望结果:
| employee | property_name | property_value |
|:--------:|:--------------|:---------------|
| 16 | Salary | 28,000 |
| 16 | Department | 12 |
| 17 | Salary | 38,000 |
| 17 | Department | 8 |
| 18 | Salary | 28,000 |
| 18 | Department | 12 |
我见过一些使用变量的线程。我能以某种方式设置和引用一个可以替换insert / select的值的变量吗?
answer to this thread看起来会起作用。但我宁愿不创建和删除那样的表。
答案 0 :(得分:4)
insert into YourTable (employee,property_name, property_value)
select 18, property_name, property_value from YourTable where employee = 16