select 批次 , COUNT(1) as 号码个数
 from tb
 group by 批次 这样?

解决方案 »

  1.   

    或者
    select a.批次,
    (select count(*) from tb as b where a.批次= b.批次) as 号码个数
    from a 
      

  2.   

     select 批次 , COUNT(1) as 号码个数
     from tb
     group by 批次 
      

  3.   

    create table t1 (号码 int , 批次 int )insert into t1 
    select 123, 1 union all
    select 45 ,2 union all
    select 456 ,1create table t2 (号码 int , 批次 int )insert into t2 
    select 123, 1 union all
    select 45 ,2 union all
    select 456 ,1
     
    select 批次 ,count (号码)from (
    select * from t1 union all select * from t2
    )T group by 批次我觉得你够一个批次的表,用批次表左联接就好了
      

  4.   

    四个一样的表哇?select 批次 , COUNT(1) as 号码个数
     from 

    select 批次 , 号码 from tab1
    union all
    select 批次 , 号码 from tab2
    union all
    select 批次 , 号码 from tab3
    union all
    select 批次 , 号码 from tab4

     group by 批次 
      

  5.   


    select 批次 , COUNT(1) as 号码个数
     from 
    (
    select 批次 , 号码 from tab1
    union all
    select 批次 , 号码 from tab2
    union all
    select 批次 , 号码 from tab3
    union all
    select 批次 , 号码 from tab4
    )a
     group by 批次 修改一点点