- 我的电脑系统:Windows 10 64位
- SQL Server 软件版本: SQL Server 2014 Express
本篇博客里面使用了
scott库,如何你现在还没有添加这个库到你的服务器里面,请在查看本篇博客前,访问这篇博文来在你的服务器里面附加scott库。
distinct 的用法
distinct 的意思是:不允许重复。
select deptno from emp;
-- 14行记录 不是3行记录

select 10000 from emp;
-- 也是14行记录

select distinct deptno from emp;
--distince deptno 会过滤掉重复的deptno

select distinct comm from emp;
--distince 也可以过滤掉重复的null。或者说如果有多个null,只输出一个

select distinct comm, deptno from emp;
--把 comm 和 deptno 的组合进行过滤

select deptno, distinct comm from emp;
--error 逻辑上有冲突
执行输出错误:
消息 156,级别 15,状态 1,第 11 行
关键字 'distinct' 附近有语法错误。
5377

被折叠的 条评论
为什么被折叠?



