如何从不同的表中减去两列的总和,并将差值插入另一列

时间:2022-10-03 15:05:41

I have three tables STUDENT, STUDENTPAYMENTS, STUDENTCREDIT.

我有三个表学生,学生付款,学生评价。

In table STUDENT there is a column TotalPayableAmount, this is the amount needed to be paid by the student.

表STUDENT中有一列TotalPayableAmount,这是学生需要支付的金额。

In table STUDENTPAYMENTS there is a column TotalPaid, this is the amount paid by the students.

在表STUDENTPAYMENTS中有一列TotalPaid,这是学生支付的金额。

And in STUDENTCREDIT there is a column TotalCredit, this is where I put/insert the remaining balance of the student.

在STUDENTCREDIT中有一列TotalCredit,这是我放置/插入学生余额的地方。

Please help me to get this result:

请帮我看看这个结果:

TotalCredit = TotalPayableAmount - TotalPaid
and Group by IDNumber ..

Thanks in advance.

提前致谢。

1 个解决方案

#1


0  

You could create a view many different tables and then use the columns in a view to subtract them from each other. writing a query and subtracting the columns in a single query will be very hard. Create a view with the columns you need and then use the view to subtract the columns that you require. How yo create a view http://www.w3schools.com/sql/sql_view.asp Subtracting columns in a view https://drupal.stackexchange.com/questions/181101/subtraction-of-two-column-in-views

您可以创建一个视图许多不同的表,然后使用视图中的列来相互减去它们。编写查询并在单个查询中减去列将非常困难。使用所需的列创建视图,然后使用视图减去所需的列。如何创建视图http://www.w3schools.com/sql/sql_view.asp在视图中减去列https://drupal.stackexchange.com/questions/181101/subtraction-of-two-column-in-views

#1


0  

You could create a view many different tables and then use the columns in a view to subtract them from each other. writing a query and subtracting the columns in a single query will be very hard. Create a view with the columns you need and then use the view to subtract the columns that you require. How yo create a view http://www.w3schools.com/sql/sql_view.asp Subtracting columns in a view https://drupal.stackexchange.com/questions/181101/subtraction-of-two-column-in-views

您可以创建一个视图许多不同的表,然后使用视图中的列来相互减去它们。编写查询并在单个查询中减去列将非常困难。使用所需的列创建视图,然后使用视图减去所需的列。如何创建视图http://www.w3schools.com/sql/sql_view.asp在视图中减去列https://drupal.stackexchange.com/questions/181101/subtraction-of-two-column-in-views