我有两个表:state_current和state_snapshots。state_current恰好包含4行,即4个不同键的当前值:
+-----+-------+
| key | value |
+-----+-------+
| A | 1 |
| B | 2 |
| C | 3 |
| D | 4 |
+-----+-------+现在,我想向state_snapshots添加一行,该行在单独的列中包含每个键的值:
+---+---+---+---+
| A | B | C | D |
+---+---+---+---+
| 1 | 2 | 3 | 4 |
| 1 | 2 | 3 | 5 |
| 1 | 2 | 4 | 5 |
...
+---+---+---+---+当然,state_current中的键永远不会改变,只有值才会改变。哪个mySQL查询会创建一行,第一列是state_current中的A,第二列是state_current中的B,依此类推?
我是mySQL的新手,所以提前感谢您的帮助!
发布于 2017-01-18 22:59:29
我能想到的最简单的答案是:
insert into state_snapshots(a,b,c,d)
values ( (select value from state_current where key='A'),
(select value from state_current where key='B'),
(select value from state_current where key='C'),
(select value from state_current where key='D')
);https://stackoverflow.com/questions/41722536
复制相似问题