move one row value to another sql without deleting

2019-03-05 06:14发布

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.

0条回答
登录 后发表回答