I have two tables, one of which is for registering the products and their values, and the other for the cart. To take the purchase values of the products, they are doing the following:
SELECT (PROD.product_price * CART.cart_amount) AS ValorTotal FROM pd_cart CART
INNER JOIN pd_products PROD
ON CART.cart_id_product = PROD.product_id
WHERE CART.cart_token = 'ABBEAD63DEE08DA1EEFE753524E65F9AE81435AB369D66D37CE6F9F31255896108B2ED481D54C50DBC972D5678D60744789FE264213F0F8B7F905276D9B51647'
AND CART.cart_status = 'A';
With this query, I have the following result.
Now I need to sum the values of the Total_Value. I understand that SUM() does the sum, but how can I apply in this query?
Introducing the query you just defined as a subquery of a totals query that performs the sum you seek:
Or by doing the sum directly, since your query can still be converted to a totals query: