当前位置: 移动技术网 > IT编程>数据库>MSSQL > Sql 第一行某列减第二行某列

Sql 第一行某列减第二行某列

2019年08月02日  | 移动技术网IT编程  | 我要评论

连城书盟网上书库,04008777777,错嫁之盛世王妃txt

--1. 将结果插入临时表
select
*
into xxx
from(
select top 1 a.fqty,a.fseq
from t_sal_orderentry as a
where fqty=5
union all
select top 1 b.fqty,b.fseq
from t_sal_orderentry as b
where fqty=1
) as c

select * from xxx

--最初update
-- update xxx
-- set fqty = isnull((
-- select top 1 a.fqty
-- from xxx as a
-- where t.fseq >= fseq
-- and fqty=5
-- )-(
-- select top 1 b.fqty
-- from xxx as b
-- where t.fseq <fseq
-- and fqty=1
-- ),0)
-- from xxx as t

--将记录1减记录2 ,新增至第3行
insert into xxx
select isnull((
select top 1 a.fqty
from xxx as a
where t.fseq >= fseq
and fqty=5
)-(
select top 1 b.fqty
from xxx as b
where t.fseq <fseq
and fqty=1
),0),t.fseq
from xxx as t
where fseq=1


select * from xxx

drop table xxx

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网