Skip to content
Advertisement

Calculate sum of price from 2 table sql server

After asking about calculate the sum of the total price here and Its work but then went I add(SUM(PRICE*AMOUNT) AS TOTAL_PRICE) to create my own View, the Total_price = Expr1, It just PRICE * AMOUNT, there is no sum here.

I apply It to create a view here is the query

Here is the output

Could anyone help me out with this problem?

Advertisement

Answer

According to your problem here and the choices you provided on your previous question, pushing sum of prices from Sale_Detail to master Sale table seems more logical now. You can UPDATE (push) your master table by using the previous query with WITH function. This way, you can update total price in Sale table based on its primary key which is a foreign key in Sale_Detail as I understood.

You can adjust your grouping in Sale_Detail table according to your total price summation for the key and other column values.

Please be careful writing and posting queries with such syntax that affects the readability.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement