MySQL Forums
Forum List  »  New in 4.1: Subqueries

Re: Transpose row into column
Posted by: sai ram
Date: May 12, 2005 05:26AM

Hi .,

I got the answer at last .,But I am sure there should be some better means too.,

Anyway .,If any one is trying out to transpose data ,to convert rows into columns.,Hope this approach will help.,

Got transpose result using if condition along with group by and summing of the specific column

SELECT H.`HQ_ITEM_CODE`,
SUM(IF(RETAIL_OUTLET_ID=1,ITEM_TOTAL_STOCK,0)) AS row1,
SUM(IF(RETAIL_OUTLET_ID=2,ITEM_TOTAL_STOCK,0)) AS row2,
SUM(IF(RETAIL_OUTLET_ID=3,ITEM_TOTAL_STOCK,0)) AS row3
FROM `HQ_ITEM_RETAIL_INFO` H
where <some condition>
GROUP BY HQ_ITEM_CODE

Options: ReplyQuote


Subject
Views
Written By
Posted
56870
April 21, 2005 01:25AM
29019
April 23, 2005 11:23PM
25719
April 24, 2005 11:32PM
Re: Transpose row into column
42585
May 12, 2005 05:26AM
24705
November 21, 2005 10:16AM
18250
October 09, 2006 01:46AM
21274
January 04, 2007 05:03PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.