Home > database >  O great spirit in the circumstance that does not create a view to spell a SQL statement.
O great spirit in the circumstance that does not create a view to spell a SQL statement.

Time:09-19

Table A, there is only the identity of the id, and numeric type (1, 2) the field 1 and 2
Table B, there is A field ids, and table A id is matching, as well as A numeric (10, 2) the type of field 3
Want to achieve, to find A table of A field match to table B minus 1 id 3, the sum of all the id field is not equal to list A 2,

CodePudding user response:

Very fuzzy, please list the test table structure, test data and the desired results,

CodePudding user response:

reference 1/f, gypsy song response:
is very fuzzy, please list the test table structure, test data and the desired results,

Good!
The table name user
Field
Id - member id, a unique identifier
Mm1 - total integral
Was - integral balance

The table name order
Field
Member id id - consumption, namely the user list id
Amount, consumption amount

Find the total integral - the sum of consumption amount!=a member of the integral balance, but the case is that some members without consumption,

CodePudding user response:

Two Numbers subtraction is bad, not with
Reference:
 
Select * from [user] u where u.m m1 - u.m m2 & lt;> ISNULL ((select sum (o.a mount) from [order] o where o.i d=u.i d), 0)

CodePudding user response:

Hello World reference 3 floor, response:
two Numbers subtraction is bad, not with
Reference:
 
Select * from [user] u where u.m m1 - u.m m2 & lt;> ISNULL ((select sum (o.a mount) from [order] o where o.i d=u.i d), 0)


And I said refers to a member of the sum of consumption, income summation (mm1) - combined (the sum of (amount)) is equal to the remaining (was).

CodePudding user response:

Hello World reference 3 floor, response:
two Numbers subtraction is bad, not with
Reference:
 
Select * from [user] u where u.m m1 - u.m m2 & lt;> ISNULL ((select sum (o.a mount) from [order] o where o.i d=u.i d), 0)

The result is the same, just and great spirit expression wasn't the same, the SQL looks is effect can be achieved,
  • Related