The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups. This GROUP BY clause follows the WHERE clause in a SELECT statement and precedes the ORDER BY clause.
Let’s create a group_by method in codeigniter
Permits you to write the GROUP BY portion of your query
$this->db->group_by("userid"); // Produces: GROUP BY userid
You can also pass an array of multiple values as well.
$this->db->group_by(array("userid", "date")); // Produces: GROUP BY userid, date