At 14:24 -0500 4/27/02, dstark@stripped wrote:
>I have a table full of cell phone data with three important columns:
>ServiceNumber, ratingPeriod (1,2 or 3) and minutes. I want to run a
>query grouped by serviceNumber that gives me the sum of minutes per
>rating period for each of the numbers in the other cloumns. So the
>query result will look like this:
>serviceNumber | SUM(of minutes where ratingPeriod =1) | SUM(of
>minutes where ratingPeriod =2) | SUM(of minutes where ratingPeriod
>I was able to do this with other tools using "Transform" and "Pivot"
>commands which are not present in MySQL.
>Is this particular query possible in MySQL? If it is not possible
>with a query perhaps it would be possible to build a table in memory
>and add the three columns to it individually?
SELECT serviceNumber, SUM(IF(ratingPeriod=1,minutes,0)),
FROM tbl_name GROUP BY serviceNumber;