sql - MySQL JOIN with 3 tables and COUNT() not working -


I am having problems with my MySQL statement I need a query that is generated by the number of comments and user Calculates the number of topics. My table structure is something like this:

  table 'user' ------------- user_id user_name ... table 'topics' ------ - ------- topic_id topic_user_id ... table 'topiccomments' --------------------- topiccomment_id topiccomment_user_id ...  

So far I have been able to produce this query:

  select u.user_id, u.user_name, COUNT (t.topic_user_id) as TOPIC_COUNT, COUNT ( Tc.topiccomment_user_id) Include topiccomments such as u TC as topiccomment_count from users u.user_id = tc.topiccomment_user_id u by u.user_id = t.topic on t Where _user_id join topics like u.user_id = t.topic_user_id and u.user_id = tc.topiccomment_user_id group. User_id  

This query is executed, but the values ​​'TOPIC_COUNT' and 'topiccomment_count' are completely incorrect and I do not understand enough why.

Did I expect someone to help me here?

Change

  COUNT (DISTINCT t.topic_id) TOPIC_COUNT, Topiccomment_count as COUNT (DISTINCT tc.topiccomment_id) This number is calculated for the number of different topics and subject comments that before you match the user ID, For the topics and topic comments were counting the number of rows in the product across. 

It works in your situation, I will have two questions, this refactor in one for counting subjects and one for topic_comments because it will be more efficient.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -