Php 通过不与codeigniter中的Group by合作订购

Php 通过不与codeigniter中的Group by合作订购,php,mysql,codeigniter-3,Php,Mysql,Codeigniter 3,我是join four table,在这里我得到了正确的数据,但问题是order by在使用group by时不起作用。那么,我该怎么做呢?请帮帮我 多谢各位 使用“选择最大值”获取最大值 使用“选择最大值”获取最大值 分组语句必须在对语句排序之前使用,否则会出现MySQL错误 只需按正确的顺序排列语句: $this->db->select('notice_x_user.*,notice.*,classes.*,sub_courses.*,,notice.status as stud

我是join four table,在这里我得到了正确的数据,但问题是order by在使用group by时不起作用。那么,我该怎么做呢?请帮帮我

多谢各位

使用“选择最大值”获取最大值

使用“选择最大值”获取最大值


分组语句必须在对语句排序之前使用,否则会出现MySQL错误

只需按正确的顺序排列语句:

$this->db->select('notice_x_user.*,notice.*,classes.*,sub_courses.*,,notice.status as studentStatus,notice.date as noticeDate');
$this->db->select_max('notice.noticeID' , 'noticeID');
$this->db->from('notice_x_user');
$this->db->join('notice','notice_x_user.noticeID = notice.noticeID', 'LEFT');
$this->db->join('classes', 'classes.ClassesID = notice.classesID', 'LEFT');
$this->db->join('sub_courses', 'sub_courses.sub_coursesID = notice.sub_coursesID', 'LEFT'); 
$wheres = "(notice_x_user.userID = '".$loginuserID."' and notice_x_user.usertype = 'Support') or notice.userID = '".$loginuserID."'";
$this->db->where($wheres);
$this->db->order_by('noticeID', 'DESC'); 
$this->db->group_by('notice.noticeID');

它将按预期工作

在对语句排序之前必须使用分组语句,否则会出现MySQL错误

只需按正确的顺序排列语句:

$this->db->select('notice_x_user.*,notice.*,classes.*,sub_courses.*,,notice.status as studentStatus,notice.date as noticeDate');
$this->db->select_max('notice.noticeID' , 'noticeID');
$this->db->from('notice_x_user');
$this->db->join('notice','notice_x_user.noticeID = notice.noticeID', 'LEFT');
$this->db->join('classes', 'classes.ClassesID = notice.classesID', 'LEFT');
$this->db->join('sub_courses', 'sub_courses.sub_coursesID = notice.sub_coursesID', 'LEFT'); 
$wheres = "(notice_x_user.userID = '".$loginuserID."' and notice_x_user.usertype = 'Support') or notice.userID = '".$loginuserID."'";
$this->db->where($wheres);
$this->db->order_by('noticeID', 'DESC'); 
$this->db->group_by('notice.noticeID');

它会像预期的那样工作

它的问题,你可以使用
max()
如果某个最大值需要编辑问题,你可以使用
max()
如果某个最大值不需要CI查询生成器来处理组和顺序的正确顺序?我的印象是查询生成器类应该处理正确的顺序,但是保持我们这边的整洁也没什么坏处:)我还没有在自己的沙盒上测试它管理错误序列的能力。CI查询生成器不是负责正确的组和顺序吗?我的印象是查询生成器类应该负责正确的序列,但是保持我们这边的整洁也没什么坏处:)我还没有在我自己的沙盒上测试它对错误序列的管理有多好
$this->db->group_by('notice.noticeID');
$this->db->order_by('notice.noticeID', 'DESC');