关于 Oracle中 distinct 的问题

unkind1145 2009-05-31 05:44:19
RT:

select *, count(distinct name) from table group by name

结果:

id name count(distinct name)
1 a 1
2 b 1
3 c 1

为什么报 ORA-00923: 未找到要求的 FROM 关键字
...全文
397 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
unkind1145 2009-05-31
  • 打赏
  • 举报
回复
还是有点问题

要是列数多了 而且不是id列的话

就相当于没有进行重复的筛选
superhsj 2009-05-31
  • 打赏
  • 举报
回复
select rownum,NAME from (select NAME from table group by name);
superhsj 2009-05-31
  • 打赏
  • 举报
回复
select rownum,NAME from table group by name
[Quote=引用 11 楼 unkind1145 的回复:]
table表

字段1 字段2
id name
1 a
2 b
3 c
4 c
5 b


结果要是这样的

1 a
2 b
3 c
[/Quote]
unkind1145 2009-05-31
  • 打赏
  • 举报
回复
table表

字段1 字段2
id name
1 a
2 b
3 c
4 c
5 b



结果要是这样的

1 a
2 b
3 c
heaven33 2009-05-31
  • 打赏
  • 举报
回复
不能在SELECT中显示没有进行 oder by 的列
unkind1145 2009-05-31
  • 打赏
  • 举报
回复
现在是不重复了 但是另外2列的数据显示不出来了 。。
unkind1145 2009-05-31
  • 打赏
  • 举报
回复
现在是不重复了 但是另外2列的数据显示不出来了 。。
heaven33 2009-05-31
  • 打赏
  • 举报
回复
你已经group by 了 怎么还会有重复的呢?
heaven33 2009-05-31
  • 打赏
  • 举报
回复
你可以写
select NAME, count(NAME) from table group by name

你写distinct 干什么呢
unkind1145 2009-05-31
  • 打赏
  • 举报
回复
。。

要去掉name列中的重复值 还要显示 其他2列的呀~
heaven33 2009-05-31
  • 打赏
  • 举报
回复
你可以写
select NAME, count(NAME) from table group by name

你写distinct 干什么呢
unkind1145 2009-05-31
  • 打赏
  • 举报
回复
去掉的话 没有显示name的表头和值了
heaven33 2009-05-31
  • 打赏
  • 举报
回复
你使用了count 函数 应该就不能使用* 了吧 应该只能显示name这一列
heaven33 2009-05-31
  • 打赏
  • 举报
回复
group by 的查询语句中可以使用 *么?去掉*试试

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧