我正在尝试按查询排序,但将零设置为最后。这是伪代码
$this->db->select("id,position");
$this->db->order_by('-position', 'ASC' );
$result = $this->db->get( 'SampleTable' );
Codeigniter将查询视为
SELECT `id`,`position` FROM `TABLE` ORDER BY `-position` ASC thus having an error
有什么方法可以通过 - 减去,以便查询
SELECT `id`,`position` FROM `TABLE` ORDER BY -`position` ASC
答案 0 :(得分:1)
你可以试试这个。
$this->db->select("id,position");
$this->db->order_by('(position * -1)', 'ASC' );
$result = $this->db->get( 'SampleTable' );