MySQL、Oracle中group by的用法区别
程序员文章站
2022-04-20 21:45:53
...
表结构:
表数据:
MySQL中group by的使用
1.select中包含的是group by的列
SELECT sex FROM student group by sex;
2.select中可以包含非group by的列
SELECT sex,age FROM student group by sex;
3.group by包含多个列
SELECT * FROM student group by sex,age;
Oracle中group by的使用
数据与上面的相同
1.select中包含的是group by的列
SELECT "sex" from "student" GROUP BY "sex" ;
2.select中可以包含非group by的列
SELECT "sex","age" FROM "student" group by "sex";
注意:Oralce中select不能包含非group by的列,但是可以包含非group by的列的聚合函数
3.select可以包含非group by的列的聚合函数
SELECT "sex",sum("age") FROM "student" group by "sex";
4.group by包含多个列
SELECT * FROM "student" group by "sex","age";
SELECT "sex","age" FROM "student" group by "sex","age";
SELECT "sex","age",count(*) FROM "student" group by "sex","age";
上一篇: Myeclipse的安装与使用*
下一篇: MyEclipse创建Maven工程