比方说,我有两张桌子,一张是“销售”,另一张是“股票”。
销售表如下所示:
-------------------------
| location | item | qty |
------------------------
| 1 | 11 | 1 |
| 2 | 12 | 1 |
-------------------------股票表应该是这样的:
-------------------------
| location | item | qty |
------------------------
| 1 | 11 | 90 |
| 2 | 12 | 70 |
-------------------------我希望在新表中插入两个表中"11“和"12”项的数据,并在一个名为"type“的新列中用"sales”和"stock“分隔它们:
---------------------------------
| type | location | item | qty |
---------------------------------
| sales | 1 | 11 | 1 |
| sales | 2 | 12 | 1 |
| stock | 1 | 11 | 90 |
| stock | 2 | 12 | 70 |
---------------------------------有什么想法吗?
发布于 2015-06-06 04:30:50
insert into table3 (thetype,location,item,qty) select 'sales',location,item,qty
from sales where item in (11,12)
insert into table3 (thetype,location,item,qty) select 'stock',location,item,qty
from stock where item in (11,12)https://stackoverflow.com/questions/30678753
复制相似问题