select avg(a) as 'a',avg(b) as 'b' from tbnameselect distinct * from tbname

解决方案 »

  1.   

    create table t1(a varchar(2),b int)
    insert t1
    select 'A',1 union all
    select 'A',2 union all
    select 'A',3 union all
    select 'B',2 union all
    select 'B',4
    goselect a,avg(b) as 'b' from t1 group by aselect distinct * from t1
    drop t1
    /*
    a    b           
    ---- ----------- 
    A    2
    B    3(所影响的行数为 2 行)a    b           
    ---- ----------- 
    A    1
    A    2
    A    3
    B    2
    B    4(所影响的行数为 5 行)
    */
      

  2.   

    select avg(a) a ,avg(b) b from tablenameselect distinct * from tablename
      

  3.   

    create table t1(a varchar(2),b int)
    insert t1
    select 'A',1 union all
    select 'A',2 union all
    select 'A',3 union all
    select 'B',2 union all
    select 'B',4
    create table t2(a varchar(2),b int)
    insert t2
    select 'A',1 union all
    select 'A',1 union all
    select 'A',2 
    goselect a,avg(b) as 'b' from t1 group by aselect distinct * from t2
    drop table t1,t2
    /*
    a    b           
    ---- ----------- 
    A    2
    B    3(所影响的行数为 2 行)a    b           
    ---- ----------- 
    A    1
    A    2(所影响的行数为 2 行)
    */
      

  4.   

    1. select a,
              avg(b) as 'b'
       from 表
       group by a
       order by a2. select distinct * from 表