我现在有一张表字段分别是“
companyname  状态(querystate) productname 等等现在我要写一个查询语句既要把公司的总数统计出来,又要算出状态为1的公司呢?我写了一条语句 麻烦各位大哥帮忙看看为什么不行,请各位高手指教!select companyname,count(companyname),querystate,count(querystate) , count(QueryState)as msg2 from  productcode  group by companyname ,querystate

解决方案 »

  1.   

    怕是不行!
    select count(companyname) from  productcode  //取得总数
    select count(querystate) from  productcode  where =1querystate=1
      

  2.   

    是这样的,我要在ASP中用到这张表,既要得到他的总数,还要分别得到他的两个状态的树木,有没有一种复合查询可以写出来呢?
      

  3.   

    试试这个:
    select count(companyname) as 公司总数,count(querystate)as 状态
    from  productcode 
    where querystate='1'
    group by querystate
      

  4.   

    select count(companyname) as 总数 from  productcode  
    select count(querystate) as 状态 from  productcode  where querystate='1' group by querystate