实际上是一个问题
b字段全部为null的的记录:
select id,count(b) as fcount
from table1 t1
group by id where b is null
 and not exist (select b from table1 t2 where t2.id=t1.id and t2.b is not null)查a字段都为2的记录你自己想想吧。

解决方案 »

  1.   


    “b字段全部为null的或者a字段都为2的记录”什么意思?
      

  2.   

    呵呵,按钮就是快,不过写错了一点点:
    select id,count(b) as fcount
    from table1 t1
    where b is null
    and not exist (select b from table1 t2 where t2.id=t1.id and t2.b is not null)
    group by id 
      

  3.   

    XIXI,Haiwer(海阔天空)眼好尖啊:)真的错了。
      

  4.   

    请问如何在微软的数据库 de  storeproduce中定义一个
    变量数组
    来保存
    SQL语句生成的记录集的变量数组多谢!!
      

  5.   

    Haiwer(海阔天空),icevi(按钮工厂) :运行你们的语句,都报错“Incorrect syntax near the keyword 'SELECT'.”
      

  6.   

    呵呵,楼上两位的EXIST写错了select id,count(b) as fcount
    from table1 t1
    where b is null
    and not exists (select b from table1 t2 where t2.id=t1.id and t2.b is not null)
    group by id 
    这个可以
      

  7.   

    呵呵,幸亏那时我下了,要不我只能钻抽屉里了!
    mmzxg(超级笨蛋) ,你好!
      

  8.   

    icevi(按钮工厂) 、Haiwer(海阔天空) 、mmzxg(超级笨蛋) :
    其中的b is null我看可以省略,
    select id,count(b) as fcount
    from table1 t1
    where not exists (select b from table1 t2 where t2.id=t1.id and t2.b is not null)
    group by id 
    这样也可以。
    icevi(按钮工厂) 、Haiwer(海阔天空) 、mmzxg(超级笨蛋) 你们认为呢?
    此问题回答后立即给分!
      

  9.   

    为什么?我觉得not exists (select b from table1 t2 where t2.id=t1.id and t2.b is not null)包括了b is null。
      

  10.   

    为什么?我觉得not exists (select b from table1 t2 where t2.id=t1.id and t2.b is not null)包括了b is null。
      

  11.   

    to:jhsunny() 
      你理解错了,但我解释不清楚.
    to:按钮工厂
      快来,这个我解释不清楚!
      

  12.   

    仔细想了想,是可以省,但是这个语句还是有错:(((((天哪!!!一个SQL语句出来了N个错!!!因为count(B)或为NULL,不能得到正确的值。
    这样写:
    select id,count(isnull(b,'')) as fcount
    from table1 t1
    where not exists (select b from table1 t2 where t2.id=t1.id and t2.b is not null)
    group by id 刚从洞里出来。现在还是再回去吧:(((((海兄,你自己看着办吧,55555555~~~~~~~~~~~
      

  13.   

    icevi(按钮工厂):才知道你是武汉人,很高兴,我是湖北人,不过现在北京。
    上面的是你的最终答案吗?
      

  14.   

    to jhsunny():
    是的,我测试后好象没问题了。
      

  15.   

    高手们也许吧问题想复杂了,我觉得这样挺好的,不知行否??
    select id,count(*)as fcount from test where b is null group by id
    select id,count(*)as fcount from test where a=2 group by id