我有一個查詢,我想通過SHIPPING_DATE訂購,但我得到這個錯誤:MySQL的語法錯誤:ORDER BY子句是不是在GROUP BY
QueryException in Connection.php line 770:
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression 1 of
ORDER BY clause is not in GROUP BY clause and contains nonaggregated
column 'device.devices.shipping_date' which is not functionally
dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by (SQL: select count(*) as device,
DATE_FORMAT(shipping_date,"%M %Y") as year from `devices` where
`shipping_date` is not null and `internal_use` = 0 group by `year` order by `shipping_date` asc)
我的代碼:
$sold_devices = Device::selectRaw('count(*) as device, DATE_FORMAT(shipping_date,"%M %Y") as year')
->whereNotNull('shipping_date')
->where('internal_use', '=', 0)
->groupBy('year')
->orderBy('shipping_date', 'asc')
->pluck('device', 'year');
任何幫幫我?
感謝
我認爲錯誤消息是extreemly自explanitory – RiggsFolly
這是以前的,因國有_all字段組標準SQL應在select語句too_所以你可以重命名'SHIPPING_DATE ''在'年'來解決這個問題。 –