0
한 명의 사용자 (사용자 ID : 100)에게 가장 좋은 투표 메시지를 나열해야합니다.메시지에 대한 SQL 쿼리
다음 쿼리를 시도했지만 문제가 있습니다.
SELECT t.topics, m.msg_id, SUM(v.vote) AS totalvote
FROM topics t, messages m, users u, votes v
WHERE t.topic_id=m.topic_id
and m.user_id=u.user_id
and u.user_id='100'
and v.user_id=u.user_id
and v.user_id=m.user_id
GROUP BY v.msg_id
ORDER BY totalvote DESC
LIMIT 0,10;
어떻게하면됩니까?
내 데이터베이스 구조 (간체) :
-------------------------
DB users
-------------------------
user_id (int) primary
-------------------------
DB topics
-------------------------
topic_id (int) primary
topic (varchar)
-------------------------
DB messages
-------------------------
msg_id (int) primary
topics_id (int) index
user_id (int) index
-------------------------
DB votes
-------------------------
vote_id (int) primary
msg_id (int) index
user_id (int) index
vote (int)
참고 : 내 영어가 좋지 않아 내가 실수 죄송합니다.
당신은'm.user_id = u.user_id AND v.user_id = u.user_id'를 가지고 있기 때문에 누군가 자신의 메시지로 한 투표 수만 계산합니다. – Barmar
이 정보를 제공해 주셔서 감사합니다. – webmaster