|
|
|
|
SELECT m.UsersratingPoints AS rate,
m.UsersratingIdUser, c.SpecializationName,
c.idSpecialization, a.DetailToUsersPhoto,
a.DetailToUsersName, a.idDetailToUsers,
v.UsersTypeAccount,
questions,
answers
FROM usersrating m
JOIN users v ON v.idUsers = m.UsersratingIdUser
JOIN detailtousers a ON a.idDetailToUsers = m.UsersratingIdUser
JOIN usersspecialization b ON b.UsersSpecializationIdUser = m.UsersratingIdUser
JOIN ( SELECT QuestionIdUser AS qid, COUNT( idQuestion ) AS questions
FROM question WHERE QuestionIdUser = m.UsersratingIdUser ) Q1 ON Q1.qid = m.UsersratingIdUser
JOIN ( SELECT AnswerToQuestionIdUser AS aid, COUNT( idAnswerToQuestion ) AS answers FROM answertoquestion
WHERE AnswerToQuestionIdUser = m.UsersratingIdUser ) Q2 ON Q2.aid = m.UsersratingIdUser
JOIN specializationtousers c ON c.idSpecialization = b.UsersSpecializationIdSpecialization
WHERE v.UsersTypeAccount = 1 ORDER BY rate DESC
|
Ругается на Unknown column 'm.UsersratingIdUser' in 'where clause'
Не пойму, почему не видно m.UsersratingIdUser в подзапросах? | |
|
|
|
|
|
|
|
для: OLi
(02.04.2014 в 02:06)
| | Проблема была решена так:
SELECT COUNT( DISTINCT idQuestion ) AS questions, COUNT( DISTINCT idAnswerToQuestion ) AS answers,
m.UsersratingPoints AS rate,
m.UsersratingIdUser,
c.SpecializationName,
c.idSpecialization,
d.DetailToUsersPhoto,
d.DetailToUsersName,
v.UsersTypeAccount,
d.idDetailToUsers
FROM usersrating m
LEFT JOIN question q ON m.UsersratingIdUser = q.QuestionIdUser
LEFT JOIN answertoquestion a ON m.UsersratingIdUser = a.AnswerToQuestionIdUser
LEFT JOIN detailtousers d ON m.UsersratingIdUser = d.idDetailToUsers
LEFT JOIN users v ON m.UsersratingIdUser = v.idUsers
LEFT JOIN usersspecialization u ON m.UsersratingIdUser = u.UsersSpecializationIdUser
LEFT JOIN specializationtousers c ON c.idSpecialization = u.UsersSpecializationIdSpecialization
'.$where.'
GROUP BY m.UsersratingIdUser
ORDER BY rate DESC'
|
| |
|
|
|