3.select_distinct_不重复字段组合的数据


USE SQLSERVER;
SELECT * FROM EMP;

SELECT DISTINCT MGR FROM EMP;
SELECT DISTINCT DEPTNO FROM EMP;
select distinct comm from emp;

select distinct comm, deptno from emp;
--查询不重复的值
--distinct关键字

select * from emp;

select distinct deptno from emp;

select distinct deptno as "等级" from emp;

select distinct sal from emp;

select distinct job from emp;

--NULL也是一个值,查询唯一时也把NULL算入
select distinct comm from emp;

select distinct deptno, comm from emp;
select distinct comm, deptno from emp;

select distinct job, ename from emp;

--错误的写法
select sal, distinct deptno from emp;
--distinct使用来修饰select关键字的,不是用来修饰字段的

select distinct sal, distinct deptno from emp;
--distinct使用来修饰select关键字的,不是用来修饰字段的

/*
注意:
distinct 修饰的是 select

单个字段:select distinct 查询为单个字段中不重复的
多个字段:select distinct F1, F2, F3... 查询为字段组(所有字段)中不重复的
语法:
select distinct F1, F2, F3... (单|多字段)from table;

例如:
select distinct deptno, comm from emp
来自 tmp表 查询 deptno, comm组合起来不包含重复数据 

语意:
来自table中查询的字段不包含重复数据(单|多字段)的组合
*/

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM