2012-04-18 85 views
0

我有以下SQL:SQL + Ion Auth + CodeIgniter?

SELECT (
(SELECT SUM(vote_score) 
FROM question_votes 
JOIN questions 
ON vote_question = q_id 
JOIN users 
ON q_author = users.id 
WHERE q_author` = users.id) 
+ 
(SELECT SUM(vote_score) 
FROM answer_votes 
JOIN answers 
ON vote_answer = a_id 
JOIN users 
ON a_author = users.id 
WHERE a_author = users.id)) AS rep 

,我希望它在这里添加(离子验证的方法):

$this->db->select(
      array(
       $this->tables['users'].'.*', 
       $this->tables['groups'].'.name AS '. $this->db->protect_identifiers('group'), 
       $this->tables['groups'].'.description AS '. $this->db->protect_identifiers('group_description'), 
       "(SELECT COUNT(`a_author`) FROM `answers` WHERE a_author = users.id) + (SELECT COUNT(`q_author`) FROM `questions` WHERE q_author = users.id) AS total_posts", 
       "SELECT 
((SELECT SUM(vote_score) 
FROM question_votes 
JOIN questions 
ON vote_question = q_id 
JOIN users 
ON q_author = users.id 
WHERE q_author` = users.id) 
+ 
(SELECT SUM(vote_score) 
FROM answer_votes 
JOIN answers 
ON vote_answer = a_id 
JOIN users 
ON a_author = users.id 
WHERE a_author = users.id)) AS rep" 
      ) 
     ); 

,但我得到的跟随着错误: my error

回答

1

难道你阅读错误信息?

你有一个(`)哪里不应该有。

改变这样的:WHERE q_author” =这个users.id:WHERE q_author = users.id

+0

呀,几秒钟内张贴的问题后,我发现了错误: '(SELECT (SELECT SUM(vote_score) FROM question_votes JOIN问题 ON vote_question = q_id JOIN用户 ON q_author = users.id WHERE q_author = users.id) + (SELECT SUM(vote_score) FROM answer_votes JOIN答案 ON vote_answer = a_id JOIN用户 ON a_author = users.id WHERE a_author = users.id))AS rep' – 2012-04-18 18:49:31

+1

有时我们的头脑会变得很疲倦,以至于每个人都会明显地经过... ..) – Gerep 2012-04-18 18:50:16

相关问题