Home > database >  Two SQL table subtraction
Two SQL table subtraction

Time:11-08

Table A:

S1... SL
Factory 1 5
Factory 2 6
Factory 3 3

Table B:

S1 SL
Factory 1 4
Factory 2 6

Table C:

S1... SL (field is the same as the table A)
Factory 1 1
Factory 3 3

Table A and table B is presupposed by table C, such as sl is 0, then don't show, such as table data does not exist in table B, is shown in table C directly, the database is SQL server,

CodePudding user response:

SELECT
A.F a.F (1, 2, 3 a.F, a.F SL - isnull (b. SL, 0) AS SL
The FROM B1 AS a
LEFT the JOIN B2 AS b ON 1=a.F b. 1
WHERE a.F SL - isnull (b. SL, 0) & gt; 0
  • Related