连城书盟网上书库,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
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
数据库SQL---数据库、基本表、视图、索引的定义、修改、删除
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (上)
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (下)
网友评论