select lotissue, lotcode,Nocount=(select count(lotissue) from lot3d where lotissue>(select lotissue from lot3d where lotcode='071'))
from lot3d where lotcode='071' 
表中有两个字段:lotissue,lotcode,要查询lotissue,lotcode再加一列显示有多少期没出了!
如果返回结果只有一个,那么在查询分析器中就能查询成功,如果返回结果多个,则显示 
“子查询返回的值多于一个。当子查询跟随在 =、!=、<、<=、>、>= 之后,或子查询用作表达式时,这种情况是不允许的。”

解决方案 »

  1.   

    邏輯上出問題了,添加聚合函数,用in 或not in,top 1 ....
      

  2.   

    select lotissue, lotcode,
    Nocount=(select count(lotissue) 
    from lot3d where lotissue>(select max(lotissue) from lot3d where lotcode='071') )
    from lot3d where lotcode='071'  
      

  3.   

    LS的,这个只是返回了一个最大的期号,还是不如我意,还有好点的办法吗?
    就是每条记录后面的NOcount都是和自己的期号相关的!