move one row value to another sql without deleting the last row

蓝咒 提交于 2019-12-04 06:17:52

问题


I currently have a temporary table like so

DBName API50 CounterValue
NULL    NULL   1
test1   34.5   NULL
NULL    NULL   2
test1   38.5   NULL

I want a script which will make my temporary table as below

DBName API50 CounterValue
test1   34.5   1
test1   38.5   2

I got some help from stackexchange and managed to achieve the above result by using the following script.

SELECT t1.DBName, t1.API50, t2.CounterValue
FROM MyTable t1 INNER JOIN MyTable t2 ON t1.PrimaryKey -1 = t2.PrimaryKey
WHERE t1.DBName IS NOT NULL

However, if the counter value in my table is not populated at all

DBName API50 CounterValue
NULL    NULL   NULL
test1   34.5   NULL
NULL    NULL   NULL
test1   38.5   NULL

Using the above script the first row is removed (which I don't want) like so

DBName API50 CounterValue
test1   38.5   NULL

I would want to achieve a result

DBName API50 CounterValue
test1   34.5   NULL
test1   38.5   NULL

Any help is greatly appreciated. Thanks.

来源:https://stackoverflow.com/questions/23626096/move-one-row-value-to-another-sql-without-deleting-the-last-row

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!