将Wilson Score Confidence SQL Code转换为Codeigniter活动记录

时间:2013-06-13 12:06:55

标签: php mysql sql codeigniter translation

我似乎无法将Wilson Score Confidence SQL代码翻译成Codeigniter活动记录代码。以下是Wilson Score Confidence的普通SQL:

SELECT *, ((likes+ 1.9208) / (likes + dislikes) - 
                   1.96 * SQRT((likes * dislikes) / (likes + dislikes) + 0.9604) / 
                          (likes + dislikes)) / (1 + 3.8416 / (likes + dislikes)) 
       AS ci_lower_bound FROM widgets WHERE likes + dislikes > 0 
       ORDER BY ci_lower_bound DESC;

取自:http://www.evanmiller.org/how-not-to-sort-by-average-rating.html

这是我尝试过的翻译,似乎没有用:

        $this->db->select('*, ((likes + 1.9208) / (likes + dislikes) - 1.96 * SQRT((likes * dislikes) / (likes + dislikes) + 0.9604) / (likes + dislikes)) / (1 + 3.8416 / (likes + dislikes)) AS ci_lower_bound');
        $this->db->where('likes + dislikes >', 0);
        $this->db->order_by("ci_lower_bound", "desc");
        $query = $this->db->get('posts', $config['per_page'], $this->uri->segment(1)); 
        $data['results'] = $query->result(); 

结果总是空着。

2 个答案:

答案 0 :(得分:0)

1.the table name has not been specified in code "widgets"
try:
        $this->db->from('widgets');

答案 1 :(得分:0)

嗯......事实证明我的代码是正确的。 MySQL只有一些小问题:

$this->db->select('*, ((likes + 1.9208) / (likes + dislikes) - 1.96 * SQRT((likes * dislikes) / (likes + dislikes) + 0.9604) / (likes + dislikes)) / (1 + 3.8416 / (likes + dislikes)) AS ci_lower_bound');
$this->db->where('likes + dislikes >', 0);
$this->db->order_by("ci_lower_bound", "desc");
$query = $this->db->get('posts', $config['per_page'], $this->uri->segment(1)); 
$data['results'] = $query->result();