You call SUM in the column expression:
SELECT SUM((DATEDIFF(date1, date2))*daily_cost) AS total_each
FROM table1, table2, table3
WHERE bid = fk1_bid
AND vid = fk2_vid
AND bid = 2;
I recommend using JOIN notation. We cannot determine exactly how to rewrite your query using JOIN, because we don’t know which column belongs to which table, but it might look like this:
SELECT SUM((DATEDIFF(t1.date1, t2.date2))*t3.daily_cost) AS total_each
FROM table1 AS t1
JOIN table2 AS t2 ON t1.bid = t2.fk1_bid
JOIN table3 AS t3 ON t1.vid = t3.fk2_vid
WHERE t1.bid = 2;
source
share