How can I write complex sql query in Laravel Elequent Query Builder -


below shown query in sql server. working fine in sql server studio. how can write in laravel eloquent format?

i tried both db::table('price')... method , price::where()... model method. using both methods not able find average.

is limitation of eloquent query builder? best way output in laravel?

select  month([date]) date,  avg(oil) oil, avg(gas) gas,  [mydatabase].[dbo].[price]   year([date]) = 2017 group (month([date])) 

this output sql

i got answer

$result = db::select(db::raw("select  month([date]) date,  avg(oil) oil, avg(oil_parity) gas,  [mydatabase].[dbo].[price]   year([date]) = :year group (month([date]))"),['year'=>$year]);  dd($result); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -