You cannot use count and sum on joins if you group by
CREATE TABLE products (id integer);
CREATE TABLE users_rate (id integer, id_product integer, rate integer, id_user integer);
CREATE TABLE anonymous_rate (id integer, id_product integer, rate integer, ip varchar(25));
INSERT INTO products VALUES (1);
INSERT INTO products VALUES (2);
INSERT INTO products VALUES (3);
INSERT INTO products VALUES (4);
INSERT INTO users_rate VALUES(1, 1, 3, 1);
INSERT INTO users_rate VALUES(1, 2, 3, 1);
INSERT INTO users_rate VALUES(1, 3, 3, 1);
INSERT INTO users_rate VALUES(1, 4, 3, 1);
INSERT INTO anonymous_rate VALUES(1, 1, 3, '192..');
INSERT INTO anonymous_rate VALUES(1, 2, 3, '192..');
select p.id,
ifnull(
( ifnull( ( select sum( rate ) from users_rate where id_product = p.id ), 0 ) +
ifnull( ( select sum( rate ) from anonymous_rate where id_product = p.id ), 0 ) )
/
( ifnull( ( select count( rate ) from users_rate where id_product = p.id ), 0 ) +
ifnull( ( select count( rate ) from anonymous_rate where id_product = p.id ), 0 )), 0 )
from products as p
group by p.id
http://sqlfiddle.com/#!2/a2add/8
I've check on sqlfiddle. When there are no rates 0 is given. You may change that.