I want to set up a variable to calculate (income - bills) as salary, then use that salary to calculate the total amount (salary + bonus) as total when selecting columns from a table. What is the proper syntax for this in Laravel’s Query Builder?
Here is a simple example of MySQL. I just need the syntax for more complex calculations, which is hard to explain here.
SELECT (income - bills) AS salary, (income - bills + bonus) AS total FROM table_name;
I also tried this, which not working.
SELECT (income - bills) as salary, (salary + bonus) as total FROM table_name;