Jump to content

Php crosstab or pivot query


digitalalpha

Recommended Posts

I have database records as;

 

date,symbol,close price

--------------------------

01/01/2009 MSFT 10

01/01/2009 MSFT 10

01/01/2009 IBM 10

01/01/2009 MSFT 10

01/01/2009 APPL 10

 

What I need is the output as;

 

Date MSFT IBM APPL

-------------------------------

01/01/2008 10 20 30

01/01/2008 10 20 30

01/01/2008 10 20 30

01/01/2008 10 20 30

01/01/2008 10 20 30

01/01/2008 10 20 30

 

Can you help pls. Many Thx

Link to comment
https://forums.phpfreaks.com/topic/147406-php-crosstab-or-pivot-query/
Share on other sites

Hi, I did read that b4, and here is my query, but it returns zeros on v1, and v2, not sure, what I am doing wrong.

 

select PX_DATE,

IF(ID_SYMBOL='1283',PX_CLOSE,'') AS V1,

IF(ID_SYMBOL='1247',PX_CLOSE,'') AS V2

from history_px

WHERE (PX_DATE >='2007-09-01' AND PX_DATE <='2009-01-01')

AND (ID_SYMBOL = '1283' OR ID_SYMBOL = '1247')

GROUP BY PX_DATE

 

Appreciate all your kind help and support. Thx

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.