# Re: Extending my question. Was: The relational model and relational algebra - why did SQL become the industry standard?

Date: 7 Mar 2003 11:01:14 +0100

Message-ID: <3e686dea.0_at_news.ruca.ua.ac.be>

Lauri Pietarinen wrote:

*>Jan Hidders wrote:
*

>> Let's say I have a set X and I want to know the average of f(x) for all x

*>> in the set X. In the bag algebra this is straightforward: an iteration
**>> over X where you compute f(x), followed by the bag function AVG. If you
**>> simulate this with sets ( the bag {{x, x, y}} becomes {(x,2), (y,1)} )
**>> then you get an iteration followed by a grouping on the values of f(x)
**>> and then you have to compute the average over the product of every
**>> element and its cardinality. It's not trivial to recognize that this is
**>> equivalent with the previous sequence of bag operations, which is often a
**>> more efficient implementation.
**>
**>Could you clarify?
**>
**>In "SQL-speak" what would this mean?
**>
**>Something like this?
**>
**>-- "tuple bag" version
**>SELECT AVG(F(x))
**> FROM X;
**>
**>instead of
**>
**>-- "set" version
**>SELECT AVG'( fx, count )
**> FROM (
**> SELECT F(x) as fx, count(*) as count
**> FROM X
**> GROUP BY x )
**>
**>??
*

Yes. With the correction you yourself already gave that the final GROUP BY should be on fx.

- Jan Hidders