聚合函数关于group by后面字段要不要在select后面出现

2025-03-04 22:16:50
推荐回答(1个)
回答1:

group by后面的字段都要在select后面出现,以下例子仅供参考:

正确的写法:

select col1,col2,sum(col3),avg(col4) from table_name group by col1,col2;

 如果你这样写肯定报错:

select col1,col2,sum(col3),avg(col4) from table_name group by col1;