CodeIgniter:如何进行选择(不同字段名)MySQL 查询 [英] CodeIgniter: How To Do a Select (Distinct Fieldname) MySQL Query

查看:37
本文介绍了CodeIgniter:如何进行选择(不同字段名)MySQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检索字段中所有唯一值的计数.

I'm trying to retrieve a count of all unique values in a field.

示例 SQL:

SELECT count(distinct accessid) FROM (`accesslog`) WHERE record = '123'

如何在 CodeIgniter 中进行此类查询?

How can I do this kind of query inside of CodeIgniter?

我知道我可以使用 $this->db->query(),并编写自己的 SQL 查询,但我还有其他要求想要使用 $this->db->where() for.如果我使用 ->query() 虽然我必须自己编写整个查询.

I know I can use $this->db->query(), and write my own SQL query, but I have other requirements that I want to use $this->db->where() for. If I use ->query() though I have to write the whole query myself.

推荐答案

$record = '123';

$this->db->distinct();

$this->db->select('accessid');

$this->db->where('record', $record); 

$query = $this->db->get('accesslog');

然后

$query->num_rows();

应该有很长的路要走.

这篇关于CodeIgniter:如何进行选择(不同字段名)MySQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆