我是CI的新人,我有一个问题......
我的正常sql是:
$tb1 = 'se_avg';
$tb2 = 'se_school';
$sql_top = "(SELECT * FROM $tb1 ,$tb2 WHERE $tb1.sid = $tb2.sid AND gid = '$gid' AND avg_mark > $s_mark AND $tb1.year = '2014' ORDER BY avg_mark ASC LIMIT 0 , 20) ORDER BY vg_mark DESC";
我想在CI活动记录中重写它。
但是我不知道在这个sql外面添加另一个命令:
$sql_top = "(SELECT * FROM $tb1 ,$tb2 WHERE $tb1.sid = $tb2.sid AND gid = '$gid' AND avg_mark > $s_mark AND $tb1.year = '2014' ORDER BY avg_mark ASC LIMIT 0 , 20)
现在,我的CI活动记录是:
$tb1 = 'se_avg';
$tb2 = 'se_school';
$sql_top = $this->db
->select('*')
->from($tb1)
->join($tb2, "$tb1.sid = $tb2.sid", 'left')
->where('gid', $gid)
->where('avg_mark >', $s_mark)
->where("$tb1.year", '2014')
->order_by("avg_mark", 'asc')
->limit(20, 0);
$query = $this->db->get();
我在哪里可以添加order_by((" avg_mark",' desc')?
我尝试将其置于限制之后,但我收到了错误的数据......
也许有另一种方式?
谢谢!
答案 0 :(得分:0)
avg_mark
- > order_by(' $ tb1.avg_mark',' DESC')