with tb(a,b)as(
select t.No,t.DocNo
  from   student t,doc p
  where t.No=p.No
  group by  t.No,t.DocNo
)
select DISTINCT A NO,case when 
(select COUNT(b) from tb where b.a=a)>1 
then '已' else '未' end DocNo
from tb b

解决方案 »

  1.   

    首先,谢谢你的回答,你这个写法看不太懂,能不能解释下。
    现在想得到的是,根据NO加DocNo来判断,根据NO,DocNo分组,然后看后面的DocNo。
    分组后的数据中的DocNo只要有一个为空。那么这组就为“未”,只有这组的DocNo全部为空才为“已”,上面得到的就是
           NO              DocNo
    1 2014080003 
    2 2014080003 H2014080800001
    3 2014080009 
    4 2014080010 
    5 2014080006 
    6 2014080002
    7 2014080007 H2014080800007
    8 2014080007 H2014080800008 
                 
         NO              DocNo
    1 2014080003    未
    2 2014080009     未
    3 2014080010    未
    4 2014080006     未
    5 2014080002      未
    6 2014080007      已
      

  2.   

    select DISTINCT A NO----------这个什么意思?应该是select DISTINCT  NO   A 吧select COUNT(b) from tb where b.a=a--------这个是什么?select COUNT(b) from tb where tb.a=a
      

  3.   

    对了,数据库是sql server 2000和oracle