Create table CC as (
Choose mc, sum(s 1) as.
From CK
Group by mc
)
-Then subtract the quantity of the newly-created outbound summary table from the total inventory of table 1 to get how much A and B are left.
Select k.mc, k.s 1, c.a, k.s1-c.a.
From KC K.
Left connection cc
On k.MC=c.mc
I wrote it in Oracle, CK is outbound, KC is inventory, and CC is a new table. But the topic is in SQL statements, so although this can be achieved, it does not meet the topic.
Solution to the answer:
Choose KC. MC, KC.s 1- problem
From KC
Join (select mc, sum(s 1) as the outbound.
From CK
Group by mc)t
On KC. MC=t.MC