id  x   y  z
1   3   5  6
1   4   4  6  
1   7   5  3
2   3   5  6
2   8   3  3
2   9   4  2
2   3   5  1求1和2对应的X列的平均数和Y列的平均数

解决方案 »

  1.   

    select id,avg(x),avg(y) from tb group by id
      

  2.   

    create table tb(id int,x int,y int,z int)
    insert into tb select 1,3,5,6
    insert into tb select 1,4,4,6
    insert into tb select 1,7,5,3
    insert into tb select 2,3,5,6
    insert into tb select 2,8,3,3
    insert into tb select 2,9,4,2
    insert into tb select 2,3,5,1
    go
    select id,avg(x)avgx,avg(y)avgy from tb group by id
    go
    drop table tb
    /*
    id          avgx        avgy
    ----------- ----------- -----------
    1           4           4
    2           5           4(2 行受影响)*/
      

  3.   

    select id,avg(x),avg(y) from tb group by id
      

  4.   

    select id,avg(x),avg(y) from tb group by id
      

  5.   

    select id,avg(x),avg(y) from tb group by id
      

  6.   

    select id,avg(x),avg(y) from tb group by id
      

  7.   

    select id,avg(x),avg(y) from tablename group by id