如何根据表C中的条件将表A中的记录插入表B.
表A:
ID Name DateFrom DateTo
1 Alex 22-7-2015 26-7-2015
2 Alice 21-8-2015 25-8-2015
Run Code Online (Sandbox Code Playgroud)
表C:
ID Quarter DateFrom DateTo
1 Quater 1 1-7-2015 31-7-2015
2 Quater 2 1-8-2015 31-8-2015
Run Code Online (Sandbox Code Playgroud)
如果表A中的记录在表C中的日期范围之间,它将插入到新的表B中.
赎回是表B.
insert into redemption(staffID,staffName,department,pointsAccumulated,referrerID)
select referrerStaffID,referrerName,referrerDepartment,SUM(points),activeDirectoryID
FROM referral
WHERE NOT EXISTS (select * from redemption1 where referrerID=activeDirectoryID) group by activeDirectoryID;
Run Code Online (Sandbox Code Playgroud)
尝试这个
Insert into tableB(Id,name,datefrom,dateto)
select t1.Id,t1.name,t1.datefrom,t1.dateto from tableA as t1
inner join tableC as t2 on t1.id=t2.id
where
t1.datefrom between t2.datefrom and t2.dateto or
t1.dateto between t2.datefrom and t2.dateto
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
140 次 |
| 最近记录: |