码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-07-04 01:09:13      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

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中查询的字段不包含重复数据(单|多字段)的组合
*/

 

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

标签:

原文地址:http://www.cnblogs.com/MrTarget/p/5639255.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!