Oracle——distinct的用法
来源:互联网 发布:youtube不翻墙软件 编辑:程序博客网 时间:2024/05/17 22:54
Oracle——distinct的用法
- 博客分类:
- Oracle
下面先来看看例子:
table表
字段1 字段2 id name 1 a 2 b 3 c 4 c 5 b
库结构大概这样,这只是一个简单的例子,实际情况会复杂得多。
比如我想用一条语句查询得到name不重复的所有数据,那就必须使用distinct去掉多余的重复记录。
select distinct name from table 得到的结果是:
----------
name a b c
好像达到效果了,可是,我想要得到的是id值呢?改一下查询语句吧:
select distinct name, id from table
结果会是:
----------
id name 1 a 2 b 3 c 4 c 5 b
distinct怎么没起作用?作用是起了的,不过他同时作用了两个字段,也就是必须得id与name都相同的才会被排除。。。。。。。
我们再改改查询语句:
select id, distinct name from table
很遗憾,除了错误信息你什么也得不到,distinct必须放在开头。难到不能把distinct放到where条件里?能,照样报错。
------------------------------------------------------------------------------------------------------------
下面方法也不可行:
select *, count(distinct name) from table group by name
结果:
ORA-00979: not a GROUP BY expression
00979. 00000 - "not a GROUP BY expression"
依然报错,
group by 必须放在 order by 和 limit之前,不然会报错
------------------------------------------------------------------------------------------------------------
偶认为这样可行
select max(id), name from table group by name;
结果:
id name
1 a
2 b
4 c
5 d
参考资料:
http://www.cnblogs.com/dogxuefeng/archive/2012/06/21/2557700.html
http://stevenfeng.iteye.com/blog/841793
- Oracle——distinct的用法
- Oracle——distinct的用法
- Oracle——distinct的用法
- Oracle——distinct的用法
- Oracle -- DISTINCT的用法
- Oracle——distinct的用法(效率)
- ORACLE中的distinct的用法
- Oracle―distinct的用法
- Oracle之 distinct的用法
- 奋斗的小鸟——dogxuefeng Oracle——distinct的用法
- Oracle数据库中distinct的用法
- oracle中distinct的用法详解
- oracle distinct用法
- oracle distinct用法
- oracle distinct用法
- oracle distinct用法
- oracle 之distinct用法
- oracle中distinct用法
- Linux内核中读写文件数据的方法
- JavaScript的内置对象和函数
- HTML5的data-*自定义属性
- JAVA安装
- jsp 指令元素、脚本元素、动作元素的区别
- Oracle——distinct的用法
- 课题第五天-blastgraph载入性能测试
- 寻找数组中第K大数
- 更改ListView子项中的EditText
- Intellij Idea 使用
- Creational模式之Builder模式
- php数组函数总结-使用技巧(一)
- Android 5.0上两个签名不一致的APP不能声明相同的permission
- DevExpress.Web.ASPxGridView