欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MySQL、Oracle中group by的用法区别

程序员文章站 2022-04-20 21:45:53
...

表结构:

MySQL、Oracle中group by的用法区别

表数据:

MySQL、Oracle中group by的用法区别

MySQL中group by的使用

1.select中包含的是group by的列

SELECT sex FROM student group by sex;

MySQL、Oracle中group by的用法区别

2.select中可以包含非group by的列

SELECT sex,age FROM student group by sex;

MySQL、Oracle中group by的用法区别

3.group by包含多个列

SELECT * FROM student group by sex,age;

MySQL、Oracle中group by的用法区别

Oracle中group by的使用

数据与上面的相同

MySQL、Oracle中group by的用法区别

1.select中包含的是group by的列

SELECT "sex" from "student" GROUP BY "sex" ;

MySQL、Oracle中group by的用法区别

2.select中可以包含非group by的列

SELECT "sex","age" FROM "student" group by "sex";

MySQL、Oracle中group by的用法区别

注意:Oralce中select不能包含非group by的列,但是可以包含非group by的列的聚合函数

3.select可以包含非group by的列的聚合函数

SELECT "sex",sum("age") FROM "student" group by "sex";

MySQL、Oracle中group by的用法区别

4.group by包含多个列

SELECT * FROM "student" group by "sex","age";

MySQL、Oracle中group by的用法区别

SELECT "sex","age" FROM "student" group by "sex","age";

MySQL、Oracle中group by的用法区别

SELECT "sex","age",count(*) FROM "student" group by "sex","age";

MySQL、Oracle中group by的用法区别

 

相关标签: 数据库 Oracle