取两个表的数据,并插入到新表 [英] Fetch Data of two tables and insert to new table
问题描述
我有三个活动,我与下列名称的应用程序:结果
活动#1 结果
活动#2 结果
活动的最终
也为每一项活动,我有下列名称的表格:结果
表格#1 结果
表格#2 结果
表格最后
默认值的数量列0,用户将在运行时改变它。
我创建表格#1 和表格#2 和他们很好地工作。
我不知道我怎么可以添加表格#1行和表格#2 ,其中数量比大0到表格最后
注意:每个表的id列是PRIMARY KEY AUTOINCREMENT
INSERT INTO最终表(产品,数量)
选择产品,数量从表1WHERE数量> 0
UNION ALL
选择产品,数量从表2WHERE数量> 0;
I have three activities in my application with following names:
Activity #1
Activity #2
Activity Final
Also for each activity, I have a table with following names:
Table #1
Table #2
Table Final
Default value of Qty column is "0" and users will change it at run-time.
I've created Table#1 and Table#2 and they work fine.
I just don't know how can I add rows of Table#1 and Table#2 where "Qty" is bigger than "0" into Table Final.
Note: id column of each tables is PRIMARY KEY AUTOINCREMENT
INSERT INTO "Table Final"(Product, Qty)
SELECT Product, Qty FROM "Table #1" WHERE Qty > 0
UNION ALL
SELECT Product, Qty FROM "Table #2" WHERE Qty > 0;
这篇关于取两个表的数据,并插入到新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!