Home > database >  SQL to help solve, this is only for the actual database data is very big,
SQL to help solve, this is only for the actual database data is very big,

Time:09-26

CodePudding user response:

; With table_a as (
Select "relay" as the name, 100 as fqty
), table_b as (
Select 1 as id, 'ts - 1' as the so, "relay" as the name, 200 as fqty
Union all select 2, 'tf - 2', 'relay, 300
)
Select a. *, (case when sum_curr - total<=0 then 0 when sum_curr - totalLeft the join (
Select the name, the sum (fqty) as the total
The from table_a
Group by name
B) on a.n ame=b.n ame
Cross the apply (
Select sum (fqty) as sum_curr
The from table_b
Where name=a.n ame and idC)

CodePudding user response:

Have thousands of name, so there are also many

CodePudding user response:

The name with thousands of field values, how

CodePudding user response:

Create a schedule of the actual owe material C,
First-time initialization, generate related data,
Since then, the inventory list and send revised material list of operations to update a table records, C

No way is very good,
If according to the results, need skills, but also very slow, large amount of data the problem, the
As I said, it is necessary to code no loophole, carefully check each related place, but is ready to query the is very fast,