Jump to content

Users Rating, Total Count In Table, Avg(Ratings)


brown2005

Recommended Posts

$domain = 1;
$user = 1;

SELECT domains_ratings_domain, COUNT( * ) , AVG( domains_ratings_rating ) FROM domains_ratings
WHERE domains_ratings_domain = $domain
GROUP BY domains_ratings_domain

 

I have this code which selects:

 

domain 1

total number of ratings for domain 1 for all users

average rating for domain 1 for all users

 

what I also want to get is the rating that $user=1 has put in the table. Can this be done in the above code? or does it need to be separate? and how would I go about doing this please?

Edited by brown2005
Link to comment
Share on other sites

try

SELECT a.domains_ratings_domain, COUNT( * ) , AVG( a.domains_ratings_rating )
FROM domains_ratings a
LEFT JOIN domain_ratings b ON a.domain_ratings_domain = b.domain_ratings_domain
  AND b.domain_ratings_userid = 1
WHERE a.domains_ratings_domain = $domain
GROUP BY a.domains_ratings_domain

Edited by Barand
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.