基本聚集和分组聚集

一个代码引发的学案。。

select course_id,count(distinct id)
from takes
where year=2009 and semester='Fall' group by course_id;//正确
select course_id,count(distinct id)
from takes
where year=2009 and semester='Fall';//错误
//not a single-group group function

开始以为这两没区别啊。聚集不就这么用吗?

我们使用基本聚集是,只能选择一个tuple,

而上面的例子是两个tuple,故不可以。

因此为了可以选择多个tuple,我们引入了分组聚集(group by).


1.对于select clause 与group by clause中的tuple:

  • 出现在group by clause中的tuple 才可以出现在select clause 中(先存在前者,后者才可以用)
  • select clause中可以出现基本聚集函数,注意不是tuple,而是aggregate function.

In other words, any attribute that is not present in the group by clause must appear only inside an aggregate function if it appears in the select clause, otherwise the query is treated as erroneous

2.我们知道,oracle是 大小写 insensitive,但这并不意味着’ '引号里面的也一样。

故,‘fall’与’Fall’不相等

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值