数据格式如下:
人员编码 学历 是否最高学历
01       大学    Y
01       小学    N 
01       初中    N
02       大学    Y 
02       小学    N
02       初中    N
数据约束规则是,每个人员只能有一个最高学历。
即:每个人“是否最高学历”字段只能有一个Y
想写语句查找如下条件异常数据:
1、每个人“是否最高学历”有多个Y
2、“是否最高学历”字段为Y,但是学历字段为空

解决方案 »

  1.   

    1. select 人员编码 from 
    (select sum(decode(是否最高学历,'Y',1,0)) a,人员编码 from tablename group by 人员编码) t
    where t.a >= 2;2.select 人员编码, nvl(学历,' '),是否最高学历 from tablename where 是否最高学历 = 'Y' and 学历 is null;
      

  2.   


      select 人员编码 from tab
      where 是否最高学历='Y'
      group by 人员编码
      having count(人员编码)>1;
      
      select * from tab
      where 是否最高学历='Y' and 学历 is null;
      

  3.   


    select * from tab_name t1
    where exists (select 1 from tab_name t2 where t2.rowid <> t1.rowid and t2.是否最高学历 = 'Y' and t2.是否最高学历 = t1.是否最高学历 and  t2.人员编码 = t1.人员编码);select * from tab_name t where t.是否最高学历 = 'Y' and t.学历 is null;