我有一个带有"user_name“和”post“的数据库。如何使用CodeIgniter的db类计算每个用户名的帖子数?
在SQL中:
SELECT
user_name,
COUNT(1) as post_count
FROM posts_by_user
GROUP BY user_name在CodeIgniter中:
$this->db->select('user_name', ???????);
$this->db->from('posts_by_user');
$this->db->group_by('user_name');
$result = $this->db->query();发布于 2013-10-07 17:00:55
试一试
$this->db->select('user_name, COUNT(*) as cnt', FALSE);
$this->db->from('posts_by_user');
$this->db->group_by('user_name');
$result = $this->db->get();
return $result->result();https://stackoverflow.com/questions/19230087
复制相似问题