At 14:24 -0500 4/27/02, [EMAIL PROTECTED] 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 
>=3)
>
>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)),
SUM(IF(ratingPeriod=2,minutes,0)),SUM(IF(ratingPeriod=3,minutes,0))
FROM tbl_name GROUP BY serviceNumber;

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to