0

我有以下 SQL:

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

我希望将其添加到此处(Ion Auth 的方法):

    $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"
            )
        );

但我收到以下错误: 我的错误

4

1 回答 1

1

你读过错误信息吗?

你有一个 (`) 不应该有的地方。

更改此: WHERE q_author' = users.id 为此:WHERE q_author = users.id

于 2012-04-18T18:48:02.607 回答