Method: Sequel::Dataset#group

Defined in:
lib/sequel/dataset/query.rb

#group(*columns, &block) ⇒ Object

Returns a copy of the dataset with the results grouped by the value of the given columns. If a block is given, it is treated as a virtual row block, similar to where.

DB[:items].group(:id) # SELECT * FROM items GROUP BY id
DB[:items].group(:id, :name) # SELECT * FROM items GROUP BY id, name
DB[:items].group{[a, sum(b)]} # SELECT * FROM items GROUP BY a, sum(b)


365
366
367
368
# File 'lib/sequel/dataset/query.rb', line 365

def group(*columns, &block)
  virtual_row_columns(columns, block)
  clone(:group => (columns.compact.empty? ? nil : columns.freeze))
end