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


#1

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
.query()
.with(‘user’)
.with(‘product’)
.with(‘store’)
.select(
‘id’,
‘product_id’,
‘user_id’,
‘sub_total’,
‘cost_price’,
‘(sub_total - (cost_price * quantity)) as p’
)
.fetch()