How to perform mathematical operations on columns using lucid model's select statement


this is essentially the query i want to reproduce ====> select unit_price, cost_price, quantity, sub_total, (sub_total - (cost_price * quantity)) as profit from sales order by profit;

but when trying it in lucid model i am getting “(sub_total - (cost_price * quantity)) column not found error”

sales = await Sale
‘(sub_total - (cost_price * quantity)) as p’



If you share the corresponding migration file, we can see how your tables looks like, and thus we could help you.