1

我正在尝试获取下一行的“对齐”值并将其存储到名为 nextAlign 的字段中的当前行中。我尝试过使用分组,并且该表的唯一标识符也不一致,并且并不总是增量为 1。这是一些数据:

 type        field                        starttop startleft  length  decimals alignment
-------------------------------------------------------------------------------------------
Text      CUSTOMER DETAILS CONFIRMATION      13.00     38.00     30.00     0.00      Centre
Text      Please spare a few minutes to      15.00     2.00      30.00     0.00      Left          
Text      confirm your details as held       15.00     2.00      30.00     0.00      Wrap      
Text      on our system. You may fax the     15.00     2.00      30.00     0.00      Wrap      
Text      form to the number above.          15.00     2.00      30.00     0.00      Wrap      
Text      Any information you may supply     17.00     2.00      30.00     0.00      Left          
Text      will not be made available to      17.00     2.00      30.00     0.00      Wrap      
Text      third parties according to the     17.00     2.00      30.00     0.00      Wrap      
Text      Privacy Act.                       17.00     2.00      30.00     0.00      Wrap      
Text      Legal name:                        20.50     2.00      30.00     0.00      Left

我想要的只是一个名为“nextAlign”的列,其中包含以下数据:

nextAlign

-Left
-Wrap
-Wrap 
-Wrap
-Left
-Wrap
4

3 回答 3

2

你没有指定你的 DBMS,所以这是 ANSI SQL:

select type, 
       field, 
       align, 
       lead(align) over (order by starttop) as next_align,
       starttop,
       startleft
from the_table
于 2012-11-15T11:07:00.743 回答
0

使用 ROW_NUMBER() OVER(ORDER BY)

并以这种方式将其外部连接到相同的选择:select_1_rownumber = select_2_rownumber+1

于 2012-11-15T11:07:45.720 回答
0
with temptable as 
( select rownum
         ,type 
         ,field 
         ,starttop 
         ,startleft 
         ,length 
         ,decimals 
         ,alignment 
    from YOURTABLE )
select   t.type 
         ,t.field 
         ,t.starttop 
         ,t.startleft 
         ,t.length 
         ,t.decimals 
         ,t.alignment
         ( select tt.alignment from temptable tt where tt.rownum = t.rownum+1 ) nextalign
    from temptable t

可能对你有用。

于 2012-11-15T11:07:56.853 回答