Mysql将记录分成两行

时间:2013-08-12 09:20:29

标签: mysql

我使用以下查询从表中选择记录:

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 

如您所见,唯一的区别是查询是accNodebitamountcreditamount。但我不能在不同的查询中选择,这是不准确的。那么如何将一条记录拆分为两个具有相同index_no的行,但不同的accNodebitamountcreditamount

我想将一条记录分成两行更准确。

感谢。

0 个答案:

没有答案