使用刪減命令。sql數據廳歷庫庫存是需要使用刪減命令來減數的,SQL(StructuredQueryLanguage)是具有數據操縱和數據定義等多種功能的資料庫語扮襲搜言禪慎。
『貳』 資料庫庫存減一怎麼實現代碼jsp
資料庫庫存減伏胡一實現代碼jsp方法:
1、表裡要有庫存這個欄位。
2、每尺廳蘆次下單,都執行一次UPDATE的語句,讓庫存自陵帶己減1,並讓賣出的欄位加一。
3、根據提供的欄位,得出以下SQL語句UPDATE表名SETkucun=kucun-1,mai=mai+1。
『叄』 c#中如何實現sql兩欄位相減啊 比如在銷售系統中 賣出貨物後sql中庫存自動減少
首先賣出貨物後,貨物的數量應該減少,此時應該:數量=數量-售出數量,然後用更新語句將資料庫中的數據更新。即update 數量=數量-售出數量。右邊的數量是售出前數量,與售出數量相減後重新將值賦給數量,即售出後的數量。
如果是兩個欄位的話,首先將兩個欄位分別取出,並分別輸出到屏幕,查看結果是不是正確。如果正確,然後將兩者相減後的結果賦給一個變數,然後運用update將值更新。
『肆』 有一張銷售表和一張庫存表,怎樣用SQL實現庫存數與銷售數之間的減
看到樓主的問題,剛剛寫的一個比較簡單的,希望對樓主有用,當然也希望樓主採納!
if exists(select name from sysobjects where name='A'and type='U')
drop table A
go
create table A
(number int not null,
name varchar(20))
insert into A
values('80','燈'冊吵);
insert into A
values('21','電線');
select*from A;
if exists(select name from sysobjects where name='B'and type='U')
drop table B
go
create table B
(number int not null,
name varchar(20))
insert into B
values('70','燈');
insert into B
values('19','電線');
select*from B;
select A.number-B.number 剩臘跡余數輪姿並量, A.name
from A,B
where A.name=B.name
『伍』 SQL實現根據生產沖減庫存
with t1 as ( select *, row_number() over(partition by 物料代碼 order by 批次) rn from jywz)
,t2 as (select *, 積壓數量 lj from t1 where rn=1 union all
select t1.*, t1.積壓數量+t2.lj from t1 join t2 on t1.物料代碼=t2.物料代碼 and t1.rn=t2.rn+1)
,t3 as ( select *, row_number() over(partition by 物料代碼 order by 批次) rn from qgsl)
, t4 as (select *, 需求量緩派 lj from t3 where rn=1 union all
select t3.*, t3.需求量+t4.lj from t3 join t4 on t3.物料代碼=t4.物料代碼 and t3.rn=t4.rn+1)
select *,
case when exists(select * from t2 where t2.物料代碼=t4.物料代碼 and t2.lj>t4.lj) then t4.需求量
when (select max(lj) from t2 where t2.物料代碼=t4.物料擾咐賀代碼)>(select lj from t4 tmp where tmp.物料代碼=t4.物料代碼 and tmp.rn=t4.rn-1)
then (select max(lj) from t2 where t2.物料代碼=t4.物料代碼)-(select lj from t4 tmp where tmp.物料代碼=t4.物料代碼 and tmp.rn=t4.rn-1)
else 0
end jysl,
case when exists(select * from t2 where t2.物料代碼=t4.物料代碼 and t2.lj>t4.lj) then 0
when (select max(lj) from t2 where t2.物料代碼=t4.物料代碼)>(select lj from t4 tmp where tmp.物料代碼=t4.物簡吵料代碼 and tmp.rn=t4.rn-1)
then t4.需求量-((select max(lj) from t2 where t2.物料代碼=t4.物料代碼)-(select lj from t4 tmp where tmp.物料代碼=t4.物料代碼 and tmp.rn=t4.rn-1))
else t4.需求量
end xql
from t4
一句sql搞定,怎麼改成update這個問題留給樓主思考