Current location - Quotes Website - Collection of slogans - There are two tables, Inventory S, Table I A997, B 1234, Table II A 105, A2 13, B16, B21/kloc-0. B303 can be obtained in one SQL statement.
There are two tables, Inventory S, Table I A997, B 1234, Table II A 105, A2 13, B16, B21/kloc-0. B303 can be obtained in one SQL statement.
-First, calculate the total outbound amount in Table 2 and establish a table.

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