select s.xh,k.kc,s.xm from (select * from student a where kch=(select top 1 kch from student where xh=a.xh)) s,kc k where s.kch=k.kch and s.xh='002'

解决方案 »

  1.   

    select *
    from student a 
         left join kc on a.kch = kc.kch
         and a.kc = (select max(kc) from student where a.xh = xh)
    select *
    from student a 
         left join kc on a.kch = kc.kch
         and a.kc = (select min(kc) from student where a.xh = xh)select *
    from student a 
         left join kc on a.kch = kc.kch
         and a.kc = (select top 1 kc from student where a.xh = xh order by newid())
      

  2.   

    这个:select s.xh,k.kc,s.xm from (select * from student a where kch=(select top 1 kch from student where xh='002' and xh=a.xh)) s,kc k where s.kch=k.kch
      

  3.   

    select *
    from student a 
         left join kc on a.kch = kc.kch
         and a.kch = (select max(kc) from student where a.xh = xh)
    select *
    from student a 
         left join kc on a.kch = kc.kch
         and a.kch = (select min(kc) from student where a.xh = xh)select *
    from student a 
         left join kc on a.kch = kc.kch
         and a.kch = (select top 1 kc from student where a.xh = xh order by newid())
      

  4.   

    select s.xh,k.kc,s.xm from student s join kc k on s.kch=k.kch 
    where s.xh='002' and and a.kch = (select top 1 kc from student where a.xh = xh order by newid())
      

  5.   

    select top 1 s.xh,k.kc,s.xm from student s,kc k where s.kch=k.kch and s.xh='002'