2017-02-14 48 views
0

我想从我的SQL选择查询中删除调整行。以下是我现在所拥有的:删除调整行SQL Select Statment

Resource Date Leave  Position Hours Code 
33333 26/02/2016 Sick Leave TRNSPLNR -7  SICK      
33333 26/02/2016 Sick Leave TRNSPLNR  7  SICK      
33333 26/02/2016 Vacation TRNSPLNR  7  VAC 

这是最终的结果应该是什么:

Resource Date  Leave  Position Hours Code     
33333 26/02/2016 Vacation TRNSPLNR 7  VAC 

回答

1

假设恰好有2次这样的重复,你可以这样做:

select t.* 
from t 
where not exists (select 1 
        from t t2 
        where t2.date = t.date and 
         t2.leave = t.leave and 
         t2.resource = t.resource and 
         t2.hours = - t.hours 
       ); 

目前尚不清楚是什么导致重复,因此您可能需要在内部where子句中添加更多比较。

+0

谢谢戈登,这对我有用! – Filip