Php 在CodeIgniter中查询大多数购买的数据
事务表Php 在CodeIgniter中查询大多数购买的数据,php,sql,codeigniter,Php,Sql,Codeigniter,事务表 标题: 1PHP食谱 2C++初学者BR/> 3高级Java 4PHP食谱 5PHP食谱 6高级Java 我想创建一个从交易表中购买最多图书的列表,如上图所示,并生成如下列表: $this->db->select('Title'); $this->db->from('transaction'); $this->db->count('Title AS TitleCount'); $this->db->group_by('AssetTitle'
标题:
1PHP食谱
2C++初学者BR/> 3高级Java
4PHP食谱
5PHP食谱
6高级Java
我想创建一个从交易表中购买最多图书的列表,如上图所示,并生成如下列表:
$this->db->select('Title');
$this->db->from('transaction');
$this->db->count('Title AS TitleCount');
$this->db->group_by('AssetTitle');
$this->db->order_by('TitleCount','ASC');
$this->db->limit(4);
$temp = $this->db->get();
$temp->num_rows();
return $temp->result_array();
购买最多的:
$this->db->select('Title');
$this->db->from('transaction');
$this->db->count('Title AS TitleCount');
$this->db->group_by('AssetTitle');
$this->db->order_by('TitleCount','ASC');
$this->db->limit(4);
$temp = $this->db->get();
$temp->num_rows();
return $temp->result_array();
但结果不是我想要的。代码点火器无法识别计数。我不太了解这个查询,所以如果有人能帮我处理这个查询,我将不胜感激
$this->db->select('Title,count(Title) AS TitleCount',FALSE);
$this->db->from('transaction');
$this->db->group_by('AssetTitle');
$this->db->order_by('TitleCount','ASC');
$this->db->limit(4);
试试这个你试过了吗:
$this->db->order_by('count(*)、'ASC')代码>它工作!只需将ASC
更换为DESC
。谢谢@GordonLinoff您可能需要在选择中添加第二个参数FALSE
。CodeIgniter将在诸如count(Title)
之类的内容周围添加反勾号。