我需要一个包含三列GroupBy的结果,而SQL运行得很好,没有任何问题。它不执行查询。我的代码和SQL如下。
代码
$this->db->select(['trk.userid AS user_id', 'scr.course AS course_id'])
->from('mdl_scorm scr')
->join('mdl_scorm_scoes_track trk', 'scr.id = trk.scormid', 'inner')
->join('mdl_course_modules mcs', 'mcs.instance = scr.id', 'inner')
->where_in('trk.value', ['completed','incomplete','passed'])
->group_by(['scr.course', 'trk.userid', 'trk.scormid'])
->order_by('trk.userid', 'DESC');
查询语句
SELECT `trk`.`userid` AS user_id, `scr`.`course` AS course_id
FROM (`mdl_scorm` scr)
INNER JOIN `mdl_scorm_scoes_track` trk ON `scr`.`id` = `trk`.`scormid` INNER JOIN `mdl_course_modules` mcs ON `mcs`.`instance` = `scr`.`id`
WHERE `trk`.`value` IN ('completed', 'incomplete', 'passed')
GROUP BY `scr`.`course`, `trk`.`userid`, `trk`.`scormid`
ORDER BY `trk`.`userid` DESC LIMIT 0,100;
当group_by只有两列时,
->group_by(['scr.course', 'trk.userid'])
原因何在?
4条答案
按热度按时间xqk2d5yq1#
*在codeigniter中,
group_by()
* 仅适用于 * 两个字段 。一个月一个月
允许您编写查询的GROUP BY部分:
CI 3 ×
group_by()
编辑01
sh7euo9m2#
考虑模型中的原始查询。
x8diyxa73#
您也可以传递多个值的数组:
Source link
kcrjzv8t4#
使用结果数组而不是结果,如