uj5u.com熱心網友回復:
;with table_a as (
select '繼電器' as name,100 as fqty
),table_b as (
select 1 as id,'ts-1' as so,'繼電器' as name,200 as fqty
union all select 2,'tf-2','繼電器',300
)
select a.*,(case when sum_curr-total<=0 then 0 when sum_curr-total<fqty then total-sum_curr else 0-fqty end) as 欠料 from table_b a
left join (
select name,sum(fqty) as total
from table_a
group by name
) b on a.name=b.name
cross apply(
select sum(fqty) as sum_curr
from table_b
where name=a.name and id<=a.id
) c
uj5u.com熱心網友回復:
name 有幾千個,so也有很多uj5u.com熱心網友回復:
name 有上千個欄位值,怎么弄uj5u.com熱心網友回復:
創建一張實際的欠料明細表C。第一次做初始化,生成相關資料。
此后, 庫存表和發料表的增刪改操作都更新一次C表相關記錄。
沒有很好的辦法。
如果根據關聯得到結果,需要技巧,而且非常慢,資料量大了就問題的。
按我說的,需要代碼沒有漏洞,仔細檢查每個相關的地方,但做好了查詢是非常快的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/79067.html
標籤:疑難問題
下一篇:業余程式員的年度總結
