繁体   English   中英

codeigniter join 计算另一个表

[英]codeigniter join count another table

 $query=$this->db->select('*') ->from('activation') ->join('products','products.id_pro = activation.id_pro') ->join('user','user.id = products.user_p') ->order_by('id_key','DESC') ->get();
     return $query->result();  

我有这些代码,我从 3 个表 abd 连接结果,效果很好。 我需要更多的是来自 4.table 的计数行。 该表称为许可证,我需要计算带有 id_key(表激活的主键)的行数。 如何在我的代码中添加它?

尝试选择许可证列作为计数

     $query=$this->db->select('*, COUNT(license.id_key ) as license_count')
                 ->from('activation')
                 ->join('products','products.id_pro = activation.id_pro')
                 ->join('user','user.id = products.user_p')
                 ->join('license','license.id_key = table.column?')
                 ->order_by('id_key','DESC')
                 ->get();

访问对象内的计数,如: $query->result()->license_count;

     $query=$this->db->select('BaseTbl.*', 'Products.*', 'User.*', COUNT(License.id_key) as license_count)
                 ->from('activation as BaseTbl')
                 ->join('products as Products','Products.id_pro = BaseTbl.id_pro')
                 ->join('user as User','User.id = Products.user_p')
                 ->join('license as License','License.id_key = BaseTbl.id_key')
                 ->order_by('BaseTbl.id_key','DESC')
                 ->group_by('BaseTbl.id_key')
                 ->get();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM