如何查找open_id_fk
在此表中出现的次数。我在我的模型中使用以下代码。
$this->db->select('open_id_fk, COUNT(open_id_fk) as total');
$this->db->group_by('open_id_fk');
$this->db->order_by('total', 'desc');
$query = $this->db->get('voting_ip', 10);
return $query;
Expected Output:
116 - 2 occurances 118 - 1 occurances 119 - 1 occurances
Acutual Output recieved:
116- 6 occurances 118- 3 occurances 119- 2 occurances
最佳答案
只需将查询中的 COUNT(open_id_fk)
更改为 COUNT(*)
$this->db->select('open_id_fk, COUNT(*) as total');
$this->db->group_by('open_id_fk');
$this->db->order_by('total', 'desc');
$query = $this->db->get('voting_ip', 10);
关于php - mysql -codeigniter 计算某个数字出现的次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31801650/