php - mysql -codeigniter 计算某个数字出现的次数

标签 php mysql codeigniter

如何查找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;

enter image description here

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/

相关文章:

mysql - 删除、截断或删除以清除 MySQL 中的表

mysql - 无法使用 Zend Framework 连接到外部数据库,但 mysql_connect 可以工作

php - 使用 SMTP codeigniter 发送电子邮件

javascript - 如何在 javascript 中插入带有 innerHTML 的 php 数组

php - Composer 无法在 symfony 4 上要求 symfony/symfony

java - JDBC/MySQL : How to check if a database or relation exists when creating one, 如果确实如此,则打印出错误

mysql - 使用 Codeigniter 的事件记录模式进行 UNION 查询

php - $_GET 变量在 mod_rewrite 将 .html 重写为 .php 时消失

php - Infusionsoft 添加联系人时出错(isdk)

php - Codeigniter REST API key 不起作用