Abrar Jahin Abrar Jahin - 2 years ago 129
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.

Answer Source

You need something like this

Student::select( DB::raw('student, ((SUM(mark1)+SUM(mark2))/SUM(mark3)) AS avg ')->get();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download