我正在尝试从Laravel 5.5数据库中返回所有用户,并按照他们这样注册的月份对它们进行分组..
class AddAttachmentThumbnailToDatabanks < ActiveRecord::Migration[4.2]
def self.up
change_table :databanks do |t|
t.attachment :thumbnail
end
end
def self.down
remove_attachment :databanks, :thumbnail
end
end
但是这给了我一个错误
$users = DB::table('users')
->orderBy('created_at')
->groupBy(DB::raw("MONTH(created_at)"))
->get();
我哪里错了?
**更新**
我得到的确切错误消息是......
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column
答案 0 :(得分:0)
您可以尝试:
$users = DB::table('users')
->select('name','email',DB::raw('MONTH(created_at) month'))
->orderBy('created_at', 'asc')
->groupby('month')
->get();