Abrar Jahin Abrar Jahin - 5 months ago 22x
SQL Question

Laravel Query Builder - Convert MySQL quert to Laravel Query Builder

I have a query in MySQL:

SELECT student, ((SUM(mark1)+SUM(mark2))/SUM(mark3)) AS avg FROM your_table


SELECT student, (mark1+mark2-mark3) AS result FROM your_table

I like to convert them to Laravel's query builder format query.

But I can't find any way to do that.


You need something like this

Student::select( DB::raw('student, ((SUM(mark1)+SUM(mark2))/SUM(mark3)) AS avg ')->get();