我有 3 张桌子A,,,BC
所有 3 个表的架构如下所述:
id, time1, place, xyz, abc, pqrs
现在两个表A都有B很多记录(大约 1000 万条)
现在A和B中的一些记录是相同的id,有些是不同的Id
现在我想将记录从A,合并B到 TableC中。合并逻辑如下
1)If records with id = someId is present only in A or B ( only in one table)
then insert record from that table (A/B depending of where its present) in table C
2)If records with id =someId is present in both A and B {
if(A.time1 > B.time2){
insert record from A into C
}else{
insert record from B into C
}
}
A我想通过在and之间使用外连接来使用单个 SQL 查询来做到这一点B。但我不是很清楚如何去做。