-1

I'm looking for an efficient way to convert data into this format like. I want to convert the data into this format like.Please Somebody help me. I'm looking for an efficient way to convert data into this format like. I want to convert the data into this format like.Please Somebody help me. This is my result:.Hi i have data like this in sql

Jan  Feb  March  Apr  May  Jun  July
1     2     3      1    4   8   9

I'm looking for an efficient way to convert data into this format like. I want to convert the data into this format like.Please Somebody help me. I'm looking for an efficient way to convert data into this format like. I want to convert the data into this format like.Please Somebody help me. This is my result:

Month   Count
Jan     1
Feb     2
March   3
Apr     1
May     4
Jun     8   
July    9

I'm looking for an efficient way to convert data into this format like. I want to convert the data into this format like.Please Somebody help me. This is my result:

DavidG
  • 113,891
  • 12
  • 217
  • 223

2 Answers2

0

Try this,

create table #Table_1
(
   Jan Int,
   Feb Int,
   March Int,
   Apr Int,
   May Int,
   Jun Int,
   July Int
)
insert into #Table_1 values(1,2,3,1,4,8,9)
select * from #Table_1

select [Month], [Count] from #Table_1
Unpivot
(
  [Count] for [Month] in ([Jan],[Feb],[March],[Apr],[May],[Jun],[July])

) as UnPvt
PP006
  • 681
  • 7
  • 17
0

try this:

 $r=mysql_fetch_assoc(mysql_query("select * from your_table limit 1")));
    if($r)foreach($r as $k=>$v){
       $rr= mysql_query("insert into target_table(collumn_name1,collumn_name2) values ('$k','$v')");
    }
Ahosan Karim Asik
  • 3,219
  • 1
  • 18
  • 27