SQL 数据库 学习 019 查询-02 distinct 的用法 --- 不允许重复


  • 我的电脑系统:Windows 10 64位
  • SQL Server 软件版本: SQL Server 2014 Express

本篇博客里面使用了 scott 库,如何你现在还没有添加这个库到你的服务器里面,请在查看本篇博客前,访问这篇博文来在你的服务器里面附加scott库。


distinct 的用法

distinct 的意思是:不允许重复。

select deptno from emp;
    -- 14行记录 不是3行记录

Alt text


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

Alt text


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

Alt text


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

Alt text


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

Alt text


select deptno, distinct comm from emp;
    --error 逻辑上有冲突

执行输出错误:

消息 156,级别 15,状态 1,第 11 行
关键字 'distinct' 附近有语法错误。


请访问:http://www.aobosir.com/

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值