sql - Convert Data from Columns to Rows -
this question has answer here:
- sql server : columns rows 5 answers
i have table data 1 below.
id full name apples mangoes grapes 1 name1 15 19 13 2 name2 11 16 15 3 name3 12 18 11 4 name4 16 20 11 5 name5 14 19 13 6 name6 19 15 18
i wanted convert this.
id full name fruits values 1 name1 apples 15 1 name1 mangoes 19 1 name1 grapes 13 2 name2 apples 11 2 name2 mangoes 16 2 name2 grapes 15 3 name3 apples 12 3 name3 mangoes 18 3 name3 grapes 11 4 name4 apples 16 4 name4 mangoes 20 4 name4 grapes 11 5 name5 apples 14 5 name5 mangoes 19 5 name5 grapes 13 6 name6 apples 19 6 name6 mangoes 15 6 name6 grapes 18
is there possibilities can done in microsoft sql?
do unpivot
:
select * tablename unpivot([values] fruits in ([apples], [mangoes], [grapes]))u
Comments
Post a Comment