300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 数据库MySQL- 查询结果去重【distinct】

数据库MySQL- 查询结果去重【distinct】

时间:2021-09-26 06:43:23

相关推荐

数据库MySQL- 查询结果去重【distinct】

1、把查询结果去除重复记录【distinct】

注意:原表数据不会被修改,只是查询结果去重。去重需要使用一个关键字:distinctmysql> select distinct job from emp;+-----------+| job |+-----------+| CLERK|| SALESMAN || MANAGER || ANALYST || PRESIDENT |+-----------+// 这样编写是错误的,语法错误。// distinct只能出现在所有字段的最前方。mysql> select ename,distinct job from emp;// distinct出现在job,deptno两个字段之前,表示两个字段联合起来去重。mysql> select distinct job,deptno from emp;+-----------+--------+| job | deptno |+-----------+--------+| CLERK|20 || SALESMAN |30 || MANAGER |20 || MANAGER |30 || MANAGER |10 || ANALYST |20 || PRESIDENT |10 || CLERK|30 || CLERK|10 |+-----------+--------+统计一下工作岗位的数量?select count(distinct job) from emp;+---------------------+| count(distinct job) |+---------------------+| 5 |+---------------------+

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。