【发布时间】:2016-07-23 17:30:03
【问题描述】:
我有两张桌子
表 1:
process status
1 completed
2 completed
3 not completed
table 2 ;是一个从 table1 获取数据的历史表
process status
1 completed
2 completed
3 not completed
下次当数据从表 1 推送到历史表时,我只想推送状态为“未完成”的数据
这样我的历史记录表如下所示
表2(历史表)
Process status
1 completed
2 completed
3 not completed
3 completed
请帮我解决这个问题,我已经尝试过子查询,但它不适合我。
我使用了这个查询:
INSERT INTO table2
SELECT *
FROM table1
WHERE NOT (status IN (SELECT Status
FROM table2
WHERE status = 'completed'))
【问题讨论】:
标签: sql sql-server select insert