我使用以下查询从表中选择记录:
SELECT (@curRank := IF(@prevVal=stu_code, @curRank, @curRank+1)) AS 'index_no', 'ac01' as accNo, "" as debitamount, amount as creditamount,
@prevVal:=stu_code
FROM payment p,(SELECT @curRank :=0, @prevVal:=null) r
SELECT (@curRank := IF(@prevVal=stu_code, @curRank, @curRank+1)) AS 'index_no', 'ac02' as accNo, amount as debitamount, "" as creditamount,
@prevVal:=stu_code
FROM payment p,(SELECT @curRank :=0, @prevVal:=null) r
如您所见,唯一的区别是查询是accNo
,debitamount
和creditamount
。但我不能在不同的查询中选择,这是不准确的。那么如何将一条记录拆分为两个具有相同index_no的行,但不同的accNo
,debitamount
和creditamount
?
我想将一条记录分成两行更准确。
感谢。