Page 1 of 1

Another sql to csv question

Posted: Mon May 25, 2009 9:20 pm
by alex_gmail
SQL output:

name|qty|week
abc|60|1
abc|20|2
abc|80|3
abc|22|4
bfg|23|1
bfg|45|2
bfg|633|3
bfg|90|4
jhg|34|1
jhg|23|2
jhg|20|4



I need to generate the csv file like this:

week,abc,bfg,jhg
1,60,23,34
2,20,45,23
3,80,633,, <<<< notice no data for jhg in week 3.
4,22,90,20

I had received a great response in previous thread by using arrays but this time I am not sure how to get it in this particular format. Will associative array help?

Thanks
Alex B

Re: Another sql to csv question

Posted: Fri May 29, 2009 1:24 pm
by andyhoneycutt
you could just use mysql to dump the data to csv, or do you need to do this PHP-side?

-Andy

Re: Another sql to csv question

Posted: Fri May 29, 2009 6:49 pm
by McInfo
The transformation you are looking for is similar to a crosstab query (without the totals).

Related topic: (broken) Displaying two variables nested under each other

Edit: This post was recovered from search engine cache.