Home > database >  There is A demand, A field value same records, B different value fields, hope B field based on diffe
There is A demand, A field value same records, B different value fields, hope B field based on diffe

Time:11-15



Which the teacher give a code, can be realized, I was not, in the beginning, thank you

CodePudding user response:

There is no answer,,,

CodePudding user response:

reference 1st floor lizg007 response:
there is no answer,,,

If you this list assindex can only be 0, 1, and the first column appears twice, it is very simple, in case the when can
If the this form assindex has many possible, and the first column may appear many times, you'll have to use piviot line and unpiviot turned column + dynamic SQL, to implement more troublesome
Recommend an article,
https://www.cnblogs.com/zhangzt/archive/2010/07/29/1787825.html

CodePudding user response:

ASSINDE only three value 0 1 2
I use the case when tried to SELECT top 2000 freevalueid,
Case the when assindex=0 then freevalueid else 'end a,
Case the when assindex=1 then freevalueid else 'end b,
Case the when assindex=2 then freevalueid else 'end c
The from gl_freevalue
GROUP BY freevalueid, assindex


Got

CodePudding user response:

SELECT top 2000 freevalueid,
Max (case when assindex=0 then freevalueid else 'end) a,
Max (case when assindex=1 then freevalueid else 'end) b,
Max (case when assindex=2 then freevalueid else 'end) c
The from gl_freevalue
GROUP BY freevalueid
  • Related