识别不正确的历史处理记录

Identify the incorrect history handled records

我在 table 中有一些数据,由于 blanks/spaces 出现在一列 segment_value_cd 中,所以历史处理不正确。

我必须从 table 中识别此类记录。

我尝试了几个查询,但它正在为我获取全部结果。

有没有办法只识别这些记录?

Sel * from party_segment where party_id in(6303031,6824664,216502393,6916270)
    id  Segment_Type_Cd Segment_Value_Cd    Segment_Start_Dt    Segment_End_Dt
    6,303,031   MB                             3/20/2013           6/7/2015
    6,303,031   MB         ?                    6/7/2015            ?
    6,824,664   MB                             3/20/2013           6/7/2015
    6,824,664   MB          ?                     6/7/2015          ?
    6,916,270   MB         ?                      9/28/2015         ?
    6,916,270   MB                             3/20/2013        9/28/2015
    216,502,393 NR        ?                       6/7/2015             ?
    216,502,393 NR                           8/7/2010          6/7/2015

感谢您的帮助!!

编辑:

查询也在获取这个派对。然而这里的历史得到了处理,因为 segment_type_cd 被改变了。

23,707  KA          7/11/2010   3/6/2011    
23,707  NM          3/6/2011    6/29/2011   
23,707  KA          6/29/2011   3/25/2014   
23,707  MB          3/25/2014   5/29/2014   
23,707  KA          5/29/2014   6/7/2015    
23,707  MB  LC      6/7/2015    9/28/2015   
23,707  KA  ?       9/28/2015         ?     

我的要求是仅获取 segment_type_cd 保持不变且历史记录基于空白和空 segment_value_cd 处理的那些方 然后将这两个记录合并为一个。就像下面的那个。我必须识别这些并合并为一个。

1   6,824,664   MB          3/20/2013   6/7/2015    
2   6,824,664   MB  ?        6/7/2015   ?         

这应该 return 任意两个连续的空字符串和任意顺序的 NULL 行:

qualify -- within two rows there's both
        -- an empty string
   max(Segment_Value_Cd)
   over (partition by party_id, Segment_Type_Cd
         order by Segment_Start_Dt
         rows 1 preceding) = '' 
and      -- and a NULL
   min(case when Segment_Value_Cd is null then '*' end)
   over (partition by party_id, Segment_Type_Cd
         order by Segment_Start_Dt
         rows 1 preceding) is not null