Calculated field from 3rd table
Posted: 2021-05-31 19:17
Hello to all the team here, quick question
I have 3 tables:
1. is table subscriptions that has some fields and a total price field that I want to be calculated
2. Subscription Services that has the fields: id, subscription id (lookup field (id) from table subscriptions) Service and price (both lookup fields from the 3rd table)
3. Services that has the fields service name and price
So I want the field Total price from Table Subscriptions to be the SUM of the records that are in the subscription services table related to the specific subscription id, the problem is that the SQL Query is taking the id of the second table and not the price. Please help me because I don't know how to make SQL Queries
The Query helper made me thiw query but I think that something is missing
SELECT SUM(`Subscription_Services`.`Price`) FROM `Subscription_Services`
LEFT JOIN `Subscription_Services` ON `Subscription_Services`.`Subscription_id`=`Subscriptions`.`id`
WHERE `Subscriptions`.`id`='%ID%'
I have 3 tables:
1. is table subscriptions that has some fields and a total price field that I want to be calculated
2. Subscription Services that has the fields: id, subscription id (lookup field (id) from table subscriptions) Service and price (both lookup fields from the 3rd table)
3. Services that has the fields service name and price
So I want the field Total price from Table Subscriptions to be the SUM of the records that are in the subscription services table related to the specific subscription id, the problem is that the SQL Query is taking the id of the second table and not the price. Please help me because I don't know how to make SQL Queries
The Query helper made me thiw query but I think that something is missing
SELECT SUM(`Subscription_Services`.`Price`) FROM `Subscription_Services`
LEFT JOIN `Subscription_Services` ON `Subscription_Services`.`Subscription_id`=`Subscriptions`.`id`
WHERE `Subscriptions`.`id`='%ID%'