Welcome Guest, Not a member yet? Register   Sign In
help after count() data
#5

[eluser]Michael Wales[/eluser]
Code:
SELECT users_groups.COUNT(`user`) AS total, groups.title FROM users_groups LEFT JOIN groups ON (groups.id = users_groups.group) GROUP BY `group` ORDER BY total DESC

Code:
$this->db->select('COUNT(`user`) AS total', FALSE);
$this->db->join('groups', 'groups.id = users_groups.group');
$this->db->group_by('group');
$this->db->order_by('total DESC');
$this->db->get('users_groups');

Off the top of my head I can't guarantee that the ORDER BY will work (since total is just an alias) and I don't feel like opening Query Browser to test it. This will give you a good starting point though.


Messages In This Thread
help after count() data - by El Forum - 05-11-2009, 02:27 AM
help after count() data - by El Forum - 05-11-2009, 02:29 AM
help after count() data - by El Forum - 05-11-2009, 02:36 AM
help after count() data - by El Forum - 05-11-2009, 02:42 AM
help after count() data - by El Forum - 05-11-2009, 05:23 AM



Theme © iAndrew 2016 - Forum software by © MyBB