MySQL Forums
Forum List  »  General

Re: Is this a cross tab/pivot table, or what?
Posted by: Peter Brawley
Date: April 03, 2006 12:24PM

I see, your terminology misled me--we usually think of tables as many-to-many, not columns.

Your queries don't need pivot tables. They're just simple aggregate queries, eg the first one is ...

SELECT
staff_id,
customer_id,
COUNT(rental_id)
FROM rental r1
GROUP BY staff_id,customer_id
HAVING COUNT(rental_id) > 1;

and the others follow the same pattern--count (or sum, or whatever aggregate func you like) within groups, on whatever criterion you like.

You need pivot tables (crosstabs) when you want to cross tabulate rows and column values. There are a couple of examples at http://www.artfulsoftware.com/queries.php.

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.