我在SQL Server中有一个类似于下表的表格:
ID Value
A 5
B 1
C 2
D 3我需要插入一个ID为'E‘的新行,该行的值是A.Value-D.Value,即(5-3=2)输出。
ID Value
A 5
B 1
C 2
D 3
E 2发布于 2017-01-19 11:10:34
使用max和insert获取行的值。这假设表中A和C只能有一个值。
insert into tablename (id,value)
select 'E',
max(case when id='A' then value end) - max(case when id='C' then value end)
from tablenamehttps://stackoverflow.com/questions/41733044
复制相似问题