DECLARE @ SQL VARCHAR (500)
The SET @ SQL='select name'
SELECT SQL + SQL=@ @ ', Max (case course when ' ' '+ + course' ' 'then score else 0 end) [' + + course'] '
The from (SELECT DISTINCT course from TB) a
SQL=SET @ @ + SQL ', the sum (score) score, cast (avg (mark * 1.0) as a decimal (18, 2)) average from TB group by the name '
The exec (@ SQL)
CodePudding user response:
If you have received, turn to cycle the column don't have to, also general,Need transfer line column data couldn't be more right, local circulation, bju international once completed,
In CSDN time not waiting for the answer early finish write cycle code also brought several rounds of testing,