tsql - How to use Unpivot Using SQL -
I am trying to use the unpivot function, but if this is the right way because I can not find the desired result I'm not sure
  Code TYPE1 type2 TYPE3 AMOUNT 1 x X Y D RE 22 2 LY GD DD 45 3 SD DFD WW 75   : Here's what I have as an example and here after the desired result I have run my query:  
  Code GRP_NM GRP_VALUES AMT1 TYPE1 XX 22 2 TYPE1 LY 45 3 TYPE1 SD 75 1 Type2 YD 22 2 type2 GD 45 3 type2 DFD 75 1 TYPE3 RE 22 2 TYPE3 DD 45 3 TYPE3 WW 75    And the query I have here but my result is that I do not need: < / P> 
  Selection code, AMT, MY_TABLE unprivate from GRP_NM (Mark (TEP1, Type 2, Type 3));    I think this is the syntax you want:  < Pre>  as my_table (type 1 as the 1 code, as type1, type1, 'y d' type2 as 'xx', 're', 22 as the form of zodiac In) selection code, grp_num, grp_values, zodiac My_table unpivot (in grp_num for grp_values (TYPE1, TYPE2, TYPE3));    Personally, I think  looks unpivot  to remember the syntax quite hard, so I usually do a  cross  Using this action to take action and  case  statement.   
 
Comments
Post a Comment