0
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"); 
4

2 回答 2

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();
于 2013-08-28T14:24:15.043 回答
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();
于 2013-08-29T07:08:19.563 回答