重新排序数据库表中的事务

时间:2014-01-13 07:30:11

标签: sql teradata

我在Teradata数据库中有一些数据需要重新排序其事务序列,以便事务显示如下:

+------+---------+-----+----+-----+
|Tx_Seq|Tx_Date  |O/Bal|Qty |C/Bal|
+------+---------+-----+----+-----+
|1     |1/08/2012|0    |500 |500  |
+------+---------+-----+----+-----+
|1     |2/08/2012|500  |-100|400  |
+------+---------+-----+----+-----+
|1     |3/08/2012|400  |250 |650  |
+------+---------+-----+----+-----+
|2     |3/08/2012|650  |100 |750  |
+------+---------+-----+----+-----+
|3     |3/08/2012|750  |-400|350  |
+------+---------+-----+----+-----+
|4     |3/08/2012|350  |-100|250  |
+------+---------+-----+----+-----+
|1     |4/08/2012|250  |200 |450  |
+------+---------+-----+----+-----+
|1     |5/08/2012|450  |100 |550  |
+------+---------+-----+----+-----+

目前看起来像这样:

+------+---------+-----+----+-----+
|Tx_Seq|Tx_Date  |O/Bal|Qty |C/Bal|
+------+---------+-----+----+-----+
|1     |1/08/2012|0    |500 |500  |
+------+---------+-----+----+-----+
|1     |2/08/2012|500  |-100|400  |
+------+---------+-----+----+-----+
|3     |3/08/2012|400  |250 |650  |
+------+---------+-----+----+-----+
|2     |3/08/2012|650  |100 |750  |
+------+---------+-----+----+-----+
|4     |3/08/2012|750  |-400|350  |
+------+---------+-----+----+-----+
|1     |3/08/2012|350  |-100|250  |
+------+---------+-----+----+-----+
|1     |4/08/2012|250  |200 |450  |
+------+---------+-----+----+-----+
|1     |5/08/2012|450  |100 |550  |
+------+---------+-----+----+-----+

请注意,对于2012年3月3日的o / Bal,tx_seq超出正常排序范围。我已经尝试过分析功能,例如将1前置和1前置的ROWS作为重新排序但无法使其工作的手段。有谁知道怎么做?

0 个答案:

没有答案