SELECT *, SUM(`Relaxation_rating` + `Food_rating`) AS Ratings
GROUP BY CODE
ORDER BY Ratings DESC
FROM destinations
如何在CodeIgniter中将此sql代码转换为CctiveRecord?
我尝试了以下方法,但确实显示了任何结果。
$this->db->select("'(SELECT *, SUM(Relaxation_rating + Food_rating) FROM database GROUP BY CODE') AS Ratings", FALSE);
$this->db->get("database");
答案 0 :(得分:1)
尝试:
$data = $this->db->select('*, SUM(`Relaxation_rating` + `Food_rating`) AS Ratings', false)->group_by('CODE')->order_by('Ratings', 'desc')->get('destinations')->result_array();
或者,
$this->db->select('*, SUM(`Relaxation_rating` + `Food_rating`) AS Ratings', false)->group_by('CODE')->order_by('Ratings', 'desc')->get('destinations')->result();
答案 1 :(得分:0)
尝试
$this->db->select('*, SUM(`Relaxation_rating` + `Food_rating`) AS Ratings');
$this->db->from('destinations');
$this->db->group_by('CODE');
$this->db->order_by('Ratings','desc');
$result = $this->db->get();