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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.