studentid inst_n0 1st_pay 2nd_pay 3rd_pay 4th_pay
50 4 22/02/2011|25000|Y 08/04/2011|17500|Y|5 22/01/2012|25000|N|27 22/04/2012|17500|N|26
我想这样: -
studentid inst_no payment pay_n0
50 4 22/02/2011|25000|Y 1st_pay
50 4 08/04/2011|17500|Y 2nd_pay
50 4 22/01/2012|25000|N 3rd_pay
50 4 22/04/2012|17500|N 4th_pay
请帮帮我......
答案 0 :(得分:-1)
select studentid, inst_no, 1st_pay as 'payment', '1st_pay' as 'pay_n0' from tableName
union
select studentid, inst_no, 2st_pay as 'payment', '2st_pay' as 'pay_n0' from tableName
union
select studentid, inst_no, 3st_pay as 'payment', '3st_pay' as 'pay_n0' from tableName
union
select studentid, inst_no, 4st_pay as 'payment', '4st_pay' as 'pay_n0' from tableName