Jump to content

[SOLVED] Complex Left Join and Counting...


ionik

Recommended Posts

OK!

 

What i need to do is I have 2 MySQL Tables one holds information for channel data and another holds the video data tracking data the tables are linked between the channelId's the thing i need to do

is sort out the channels by the videos that have the highest rating and the rating are stored in a new row for each one here is a graph to better explain it

 

VideoTracking

---------------------------

videoId | channelId | rating

---------------------------

    2    |      1      |    2

---------------------------

    2    |      1      |    3

---------------------------

    1    |      3      |    5

---------------------------

    1    |      3      |    1

---------------------------

 

So as you see I need to add all of the values for videos ratings and then sort by that how would i DO this?

Link to comment
Share on other sites

NEVERMIND I solved the problem........here is the sql statement just incase anyone else runs into this problem

 

SELECT DISTINCT ch.channelId, ch.name, CEIL(SUM( vr.rating ) / COUNT(vr.rating)) as rating FROM '.CHANNELS.' ch RIGHT JOIN '.VIDEO_RATINGS.' vr ON vr.channelId = ch.channelId GROUP BY ch.channelId ORDER BY rating DESC

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.