On 2014-11-09 10:37 AM, Steffan A. Cline wrote:
Looking for suggestions on how to best pull some data.

I need to do some calcs but pull the data by year and month to make a
table like such.

                2012    2013    2014
Jan             $243    $567    $890
Feb             $123    $456    $908
Mar             S(      S(      S(
Apr
May

Assuming date column d and column being summed named qty ...

select monthname(d), sum( if( year(d)=2012, qty, 0 ) ) as '2012', sum( if( year(d)=2013, qty, 0 ) ) as '2013', sum( if( year(d)=2014, qty, 0 ) ) as '2014'
from tbl
group by month(d)
order by month(d);

See "Pivot tables"at Common MySQL Queries <http://www.artfulsoftware.com/queries.php>

PB

----
S(


I can get the data to be ordered by year, month but as you know that is
not easily conducive to putting it into an HTML table without some middle
ware storing and iterating through found sets.

Suggestions?


Thanks,
Steffan

---------------------------------------------------------------
T E L  6 0 2 . 7 9 3 . 0 0 1 4 | F A X  6 0 2 . 9 7 1 . 1 6 9 4
Steffan A. Cline                        stef...@execuchoice.net
http://www.ExecuChoice.net                 Phoenix, Arizona USA
---------------------------------------------------------------




Reply via email to