MySQL Forums
Forum List  »  General

Re: Is this a cross tab/pivot table, or what?
Posted by: Peter Brawley
Date: April 04, 2006 05:06PM

1:1, 0:1, 1:many and many:many usually refer to relationships between tables, not between columns. Relations between columns are usually described in terms of dependence/independence.

In the sakila db (see the diagram at http:www.stardata.it/sakila/sakila.html), the customer:rental, inventory:rental and staff:rental relations are each 1:many. A many:many relationship, in fact, needs a bridge table between the two tables to decompose the many:many relationship into two 1:many relationships.

But I think that's not your problem. Your problem, if I understand it, has to do with GROUPs. (To answer your question about GROUP BY, it's really dead simple: SQL applies an aggregating function (eg SUM,MAX,MIN,etc) to groups of column values defined by the GROUP BY clause.) But if I understand you aright, you are not after a simple GROUP BY. Instead, you wish to apply _within-group_ calculations. The question is so often asked, it's acquired a name of its own (at least in the MySQL community), "the groupwise max problem", even though the aggregating function one wishes to apply within groups isn't necessarily MAX().

There are examples at http://www.artfulsoftware.com/queries.php under "Groupwise minimum" and "Groupwise quotas". There also an example from the MySQL general Discussion list at http://archives.neohapsis.com/archives/mysql/2006-q1/0819.html.

Unfortunately the data in sakila.rental doesn't lend itself to groupwise calculations. (Rental_date would be a natural, but the populate script sets all rental dates to the time the populate script runs, which is useless.) Perhaps you would post some CREATE TABLE and INSERT statements so we can see what you're working with?

PB

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.