两个表
基本信息表a:pid(个人编号),,name(姓名),age(年龄),dept(部门),senior(上司)
支援认知信息表b:id(个人编号),job(职位),每个人允许多条记录要求:
1 查询年龄为30岁以上且任职数为两个以上的所有人员的基本信息
2 查询所有既有上司又有下属的职员的基本信息

解决方案 »

  1.   

    1:select a.* from 基本信息表a as a  where a.[pid] in (select id from 支援认知信息表b where count(1) as t >2 group by id)
      

  2.   


    1:  select * from a where age>30 and pid in(select id from b group by id having count(distinct job)>2)
      

  3.   

    2:select a.* from 基本信息表a as a where a.sinior is not null And (select count(1) from 基本信息表a as b where b.[senior]=a.[pid] )
      

  4.   


    2 select * from a where senior is not null 
      and exists(select 1 from a b where a.senior=a.pid)其中senior 是上司ID,與PID一樣.
      

  5.   

    1:select a.* from 基本信息表a as a  where a.[age]>30 a.[pid] in (select id from 支援认知信息表b where count(1) as t >2 group by id)
      

  6.   

    select a.* from 基本信息表a as a where a.sinior is not null And (select count(1) from 基本信息表a as b where b.[senior]=a.[pid] )>0