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 行) */
select avg(a) a ,avg(b) b from tablenameselect distinct * from tablename
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 行) */
1. select a, avg(b) as 'b' from 表 group by a order by a2. select distinct * from 表
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 行)
*/
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 行)
*/
avg(b) as 'b'
from 表
group by a
order by a2. select distinct * from 表