0

テーブルチケット(ユーザー名、投稿、スキーム)ユーザーが投稿する可能性があります。たとえば、

____________________________________
username  |    posts   |    scheme |
__________|____________|___________|
A         |    post1   |      10   |
__________|____________|___________|
B         |    post2   |      2    |
__________|____________|___________|
B         |    post 3  |      13   |
__________|____________|___________|
A         |    post 4  |      21   |
__________|____________|___________|
A         |    post 5  |      -1   |
__________|____________|___________|

私のクエリは、タイトルの総数と評判の合計を含む個別のユーザー名を出力する必要があります。つまり、

_______________________
|A   |   3   |   30    |
|____|_______|_________|
|B   |   2   |   15    |
|____|_______|_________|

私のモデル機能:-

function getAllUsers(){                      
        $this->db->distinct();
        $this->db->select('username,COUNT(title) AS numtitle');
        $this->db->where('site_referers_id',1);
        return $this->db->get('tbl_tickets');
     }

しかし、それはうまくいかないようです:(

4

3 に答える 3

4

$this->db->group_by()の代わりに使用する必要がありますdistinct

function getAllUsers(){                      
  $this->db->select('username, COUNT(*) AS numtitle, SUM(scheme) AS total');
  $this->db->where('site_referers_id',1);
  $this->db->group_by('username');
  return $this->db->get('tbl_tickets');
}
于 2012-07-27T08:02:37.313 に答える
2

このコードを確認してください

    $this->db->select('username,COUNT(title) AS numtitle');
    $this->db->where('site_referers_id',1);
     $this->db->group_by('username');
    return $this->db->get('tbl_tickets');

あなたは完璧な結果を得る

于 2012-07-27T08:12:11.243 に答える