0

我有一个表日志:

checktype
---------
    I
    O
    I
    o
    I
    I
    I
    o
    I
    O

现在我希望IO应该成对出现,所以我想删除多余的I,这意味着我只想要一个(I 或 O)一个接一个。该表应仅包含成对的IO。

4

2 回答 2

2

您可以很容易地通过以下查询获得此结果。

Select checktype,((ROW_NUMBER() OVER (ORDER BY checktype))*2 - 1) as Row_id From Table
Where checktype = 'I' 
UNION
Select checktype,((ROW_NUMBER() OVER (ORDER BY checktype))*2 ) as Row_id From Table
Where checktype = 'O' 
Order by Row_id

我已经测试过了,它对我有用

于 2013-09-03T10:59:12.153 回答
0

尝试这个:

ResultSet rs = stmt.executeQuery("SELECT checkType FROM myTable");
while(rs.next( )){
   if (rs.getString("checkType").equals('I'){
       if(rs.next(){
          if(rs.getString("checkType").equals('O'){
          }else{
           //delete logic  
          }           
       }
   } else if(rs.getString("checkType").equals('O'){
       if(rs.next(){
          if(rs.getString("checkType").equals('I'){
          }else{
           //delete logic  
          }           
       }
   }
}
于 2013-09-03T10:36:13.130 回答