我怎麼能在laravel 5.4自定義查詢在laravel 5
select items.id,items.name,total,region from items LEFT OUTER JOIN
(select purchases.region_id as region , sum(purchases_detail.quantity)
as total,purchases_detail.item_id
from purchases_detail
left join purchases on(purchases.id=purchases_detail.purchase_id)
GROUP BY purchases_detail.item_id) pd on (pd.item_id=items.id)
運行此類型的查詢時,我想這在DB ::選擇( '') 它給了我一個錯誤:
SQLSTATE [42000]:語法錯誤或訪問衝突:1055'amsdb.purchases.region_id'不在GROUP BY中(SQL:select items.id,items.name,total,來自項目的區域LEFT OUTER JOIN (select purchases.region_id as region,sum(purchases_detail.quantity)as total,purchases_detail.item_id f ROM purchases_detail 左連接上(pd.item_id = items.id))
上(purchases.id = purchases_detail.purchase_id) GROUP BY purchases_detail.item_id)PD購買,但它工作得很好,當我運行它的phpmyadmin
你應該在Laravel中關閉strict,並且所有東西都會按照它的樣子工作。進入'config/database.php'並在mysql配置數組中,將'strict => true'改爲'strict => false'; – Maraboc
@Maraboc不好的建議,他應該修復他的查詢。 –
@TimBiegeleisen Ithink即使他修復了查詢,他應該更新嚴格模式! – Maraboc