求SQL语句的写法解决办法
求SQL语句的写法
原来有数据
select t.No,t.DocNo
from student t,doc p
where t.No=p.No
group by t.No,t.DocNo
得到的数据是
NO DocNo
1 2014080003
2 2014080003 H2014080800001
3 2014080009
4 2014080010
5 2014080006
6 2014080002
7 2014080007 H2014080800007
8 2014080007 H2014080800007
现在想得到的是,根据NO加DocNo来判断,如果出现多个一样的NO,就看后面的DocNo是不是一样的值,如果不一样就“未”,一样就为“已”,如果为空就为“未”,上面得到的就是
NO DocNo
1 2014080003 未
2 2014080009 未
3 2014080010 未
4 2014080006 未
5 2014080002 未
6 2014080007 已
这个要怎么写呢?
------解决方案--------------------
原来有数据
select t.No,t.DocNo
from student t,doc p
where t.No=p.No
group by t.No,t.DocNo
得到的数据是
NO DocNo
1 2014080003
2 2014080003 H2014080800001
3 2014080009
4 2014080010
5 2014080006
6 2014080002
7 2014080007 H2014080800007
8 2014080007 H2014080800007
现在想得到的是,根据NO加DocNo来判断,如果出现多个一样的NO,就看后面的DocNo是不是一样的值,如果不一样就“未”,一样就为“已”,如果为空就为“未”,上面得到的就是
NO DocNo
1 2014080003 未
2 2014080009 未
3 2014080010 未
4 2014080006 未
5 2014080002 未
6 2014080007 已
这个要怎么写呢?
------解决方案--------------------
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