oracle中distinct用法
2016-03-30 15:52
711 查看
1、作用于单列
select distinct name from A
2、作用于多列
select distinct name, id from A
select distinct xing, ming from B
返回的结果为两行,这说明distinct并非是对xing和ming两列“字符串拼接”后再去重的,而是分别作用于了xing和ming列。
3、COUNT统计
select count(distinct name) from A; --表中name去重后的数目, SQL Server支持,而Access不支持
count是不能统计多个字段的,下面的SQL在SQL Server和Access中都无法运行。
select count(distinct name, id) from A;
若想使用,请使用嵌套查询,如下:
select count(*) from (select distinct xing, name from B) AS M;
4.distinct必须放在开头
select id, distinct name from A; --会提示错误,因为distinct必须放在开头
select distinct name from A
2、作用于多列
select distinct name, id from A
select distinct xing, ming from B
返回的结果为两行,这说明distinct并非是对xing和ming两列“字符串拼接”后再去重的,而是分别作用于了xing和ming列。
3、COUNT统计
select count(distinct name) from A; --表中name去重后的数目, SQL Server支持,而Access不支持
count是不能统计多个字段的,下面的SQL在SQL Server和Access中都无法运行。
select count(distinct name, id) from A;
若想使用,请使用嵌套查询,如下:
select count(*) from (select distinct xing, name from B) AS M;
4.distinct必须放在开头
select id, distinct name from A; --会提示错误,因为distinct必须放在开头
相关文章推荐
- Oracle面试题
- Oracle中的PLsql的符号解释大全
- 初用oracle 笔记
- oracle数据库各版本下载地址
- Oracle性能优化--DBMS_PROFILER
- Oracle性能优化--AUTOTRACE 操作
- oracle11.2.0.1新特性
- 关于通过导数据出现的oracle字符集问题
- 使用Oracle数据库字典表生成MyBatis配置
- Oracle11g x64使用Oracle SQL Developer报错:Unable to find a Java Virtual Machine
- 干净的卸载Oracle
- oracle 数据库信息查询
- Oracle 11G 用exp无法导出空表解决方法以及数据泵的使用
- ORACLE EXPDP命令使用详细
- Oracle 数据库基础学习 (三) Oracle 四个表结构
- oracle之spool详细使用总结(转)
- oracle nologging用法(转)
- oracle 11g impdp时 报ORA-12899(转)
- 大并发连接的oracle在Linux下内存不足的问题的分析(转)
- 如何检测被锁住的Oracle存储过程及处理办法汇总(转)