多表联合条件删除
2018-04-12 18:03 huoit 阅读(885) 评论(0) 收藏 举报
--A,B表满足条件且同时存在的数据删除 delete from table_A where exists(select 1 from table_B b where table_A.UserId=b.UserId and table_A.IdCard=b.IdCard)
--A-B;查询A表中不在B的数据 insert into B (……) select * from A where (select count(1) as num from B where A.ID = B.ID) = 0
--查询A表(包含多条重复数据)所有用户最接近目标日期的记录 select a.* from [DelByLot] a inner join (select UserId,max(CreateDate) 'maxgdtime'from [DelByLot] where datediff(day,CreateDate,'2018-4-27')>-1 group by UserId) b on a.UserId=b.UserId and a.CreateDate=b.maxgdtime
1、如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!
2、欢迎各位转载,但是未经作者本人同意,转载文章请在文章页面明显位置标明作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/xmai/
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号