关系代数 - 表示“拥有”的正确方法是什么?条款?

发布于 2024-08-17 22:11:00 字数 503 浏览 4 评论 0原文

这是作业问题的一小部分,所以我可以理解整个问题。

用于列出多次出现的汽车价格的 SQL 查询:

select car_price from cars
group by car_price
having count (car_price) > 1;

关系代数中的一般形式是 Y(gl,al)R 其中,Y 是希腊符号,gl 是要分组的属性列表,al 是聚合列表。

关系代数:

 Y (count(car_price)) cars

该语句中的 having 子句是如何编写的?有简写吗?如果不是,我只需要从该关系中进行选择吗?像这样?

SELECT (count(car_price) > 1) [Y (count(car_price)) cars]

This is a small part of a homework question so I can understand the whole.

SQL query to list car prices that occur more than once:

select car_price from cars
group by car_price
having count (car_price) > 1;

The general form of this in relational algebra is
Y (gl, al) R
where Y is the greek symbol, gl is list of attributes to group, and al is a list of aggregations.

The relational algebra:

 Y (count(car_price)) cars

How is the having clause written in that statement? Is there a shorthand? If not, do I just need to select from that relation? Like this?

SELECT (count(car_price) > 1) [Y (count(car_price)) cars]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尛丟丟 2024-08-24 22:11:00

select count(*) from (select * from cars whereprice > 1) as cars;

也称为关系闭包。

select count(*) from (select * from cars where price > 1) as cars;

also known as relational closure.

无畏 2024-08-24 22:11:00

为了或多或少准确地回答所提出的实际问题,“关系代数 - 表示‘having’子句的正确方法是什么?”,首先需要说明的是,问题本身似乎暗示或假设,存在“THE”关系代数这样的东西,但这种假设根本不真实!

代数是一组运算符,任何人都可以定义他喜欢的任何运算符集,这意味着任何人都可以定义他喜欢的任何代数!休·达文 (Hugh Darwen) 在他最近的出版物中提到 RESTRICT 并不是代数的基本运算符,尽管许多其他人确实这么认为。

特别是在聚合和摘要方面,对于如何将它们合并到关系代数中几乎没有达成共识。将诸如 COUNT() 之类的运算符(将关系作为参数值并返回整数)定义为代数的一部分,对于代数的闭包属性可能会出现问题,正是因为此类运算符不返回关系......

因此,遗憾的是,但最合适的答案似乎是,几乎不可能给出这个问题的结论性答案......

For a more or less precise answer to the actual question asked, "Relational algebra - what is the proper way to represent a ‘having’ clause?", it needs to be stated first that the question itself seems to suggest, or presume, that there exists such a thing as "THE" relational algebra, but that presumption is simply untrue !

An algebra is a set of operators, and anyone can define any set of operators he likes, meaning anyone can define any algebra he likes ! In his most recent publication, Hugh Darwen mentions that RESTRICT is not a fundamental operator of the algebra, though lots of others do consider it as such.

Especially with respect to aggregations and summaries, there is little consensus as to how those should be incorporated in a relational algebra. Defining operators such as COUNT() (that take a relation as an argument value and return an integer) as part of the algebra, might be problematic wrt the closure property of the algebra, precisely because such operators do not return a relation ...

So the sorry, but nevertheless most appropriate, answer here seems to be that a conclusive answer to this question is almost impossible to give ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文