使用关系代数中的聚合和/或组进行查询-计数,最大值,最小值等 [英] Query using aggregation and/or groups in relational algebra - count, max, min, etc

查看:222
本文介绍了使用关系代数中的聚合和/或组进行查询-计数,最大值,最小值等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在教科书上读了很多书,在互联网上浏览了很多页面,但是我不明白最小/最大,计数,...,函数/运算符如何在关系/表或元组/组上聚合关联/表中的行是使用诸如∪(联合),∩(交集),x(联接),-(减号),π(投影),....等基本操作构建的.

有人可以告诉我如何用关系代数表达这些功能/运算符吗?

解决方案

关系代数中的计算函数尚未完全包含.

在关系代数中,模式(A1,A2,... An)上的聚合操作编写如下:

  G1,G2,...,Gm g f1(A1'),f2(A2'),...,fk(Ak')(r) 

其中每个 Aj'(1≤j≤k )是原始属性 Ai(1≤i≤n )之一.

g之前的属性是分组属性,其功能类似于SQL中的"group by"子句.然后,有任意数量的聚合函数应用于各个属性.该运算被应用于任意关系r.分组属性是可选的,如果未提供分组属性,那么将在应用操作的整个关系中应用聚合函数.

我们假设我们有一个名为Account的表,该表具有三列,即Account_Number,Branch_Name和Balance.我们希望找到每个分支机构的最大余额.这是通过 Branch_NameGMax(Balance)(Account)完成的.要找到所有帐户的最高余额,而不管分支机构如何,我们可以简单地编写 GMax(Balance)(Account).

I have read much in textbooks and browsed a lot of pages on the internet but I can't understand how functions/operators like min, max, count, ... that aggregate over a relation/table or groups of tuples/rows in a relation/table are built with basic operations such as ∪ (union), ∩ (intersection), x (join), - (minus), π (projection), ....

Can anyone show me how to express these functions/operators with relational algebra?

解决方案

Computing functions in relation algebra are not fully included yet.

In relational algebra the aggregation operation over a schema (A1, A2, ... An) is written as follows:

G1, G2, ..., Gm g f1(A1'), f2(A2'), ..., fk(Ak') (r)

where each Aj', 1 ≤ j ≤ k, is one of the original attributes Ai, 1 ≤ i ≤ n.

The attributes preceding the g are grouping attributes, which function like a "group by" clause in SQL. Then there are an arbitrary number of aggregation functions applied to individual attributes. The operation is applied to an arbitrary relation r. The grouping attributes are optional, and if they are not supplied, the aggregation functions are applied across the entire relation to which the operation is applied.

Let's assume that we have a table named Account with three columns, namely Account_Number, Branch_Name and Balance. We wish to find the maximum balance of each branch. This is accomplished by Branch_NameGMax(Balance)(Account). To find the highest balance of all accounts regardless of branch, we could simply write GMax(Balance)(Account).

这篇关于使用关系代数中的聚合和/或组进行查询-计数,最大值,最小值等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆