select cp_id,(select count(*) from testtable ) from testtable;

解决方案 »

  1.   

    只能
    select cpid from testtable
    union all
    select count(*) from testtable;
      

  2.   

    select cp_id,count(*) from testtable group by cp_id;
      

  3.   

    好像没有办法避免使用两次 select 语句!
      

  4.   

    实在在避免使用两次select那你就用函数吧!呵呵。
      

  5.   

    但是一楼的办法其实还是进行了两次select操作。
      

  6.   

    只有一楼的办法对阿,这种要求本身就是就不可能一个纯粹的select操作完成的,而且应该也不建议写在一个sql语句中吧