兩個相鄰列求和

2021-05-22 09:05:18 字數 492 閱讀 5529

1     3

2     7

3     1145

6左邊這個是乙個資料表中的值,我要每兩行求和,最後的結果是右邊這個表,sql怎麼寫?

答案:if object_id('[test]') is not null drop table [test]

gocreate table [test]([t1] int)

insert [test]

select 1 union all

select 2 union all

select 3 union all

select 4 union all

select 5 union all

select 6 

select t=t1 + isnull((select top 1 t1 from test where t1>t.t1),0)  

from [test] t

where  t.t1%2=1

兩兩交換兩個相鄰節點

給定乙個鍊錶,兩兩交換其中相鄰的節點,並返回交換後的鍊錶。如 給定1 2 3 4,返回2 1 4 3。說明 方法一 交換兩個節點裡的值而節點不動。該題禁止這樣做 方法二 老老實實的交換就好了 我的 if head null return head if head.next null return h...

判斷兩個MAC位址是否相鄰

有兩個mac位址,如 fe ff fe ab ab ff 和 fe ff fe ab ab fe 它們之間相差1,則這兩個位址是相鄰的。如 fe ff fe ab ab ff 和 fe ff fe ab ab f0 則它們是不相鄰的。注意 fe ff fe ab ab ff 和 fe ff fe a...

不用 對兩個整數求和

不用 對兩個整數求和。思路 主要分成3步 第一步不考慮進製,對每一位相加。0加0與1加1的結果都0,0加1與1加0的結果都是1。我們可以注意到,這和異或的結果是一樣的。對異或而言,0和0 1和1異或的結果是0,而0和1 1和0的異或結果是1。接著考慮第二步進製,對0加0 0加1 1加0而言,都不會產...