1
Well, I’m developing a project and it has a list of people, I would like to list them based on the average of the evaluation, I tried to do with INNER JOIN and AVG, but with them will not show users who have just signed up. The SELECT that works for what I want is this:
SELECT p.idPessoa, p.nomePessoa, p.descricaoPessoa, f.nomeFoto,
(SELECT SUM(a.valorAvaliacao /
(SELECT COUNT(a.idAvaliacao) FROM tb_avaliacao as a
WHERE a.idCategoria = '$idcategoria' && a.idPessoa = '$idpessoa'
GROUP BY a.idPessoa AND a.idCategoria))
FROM tb_avaliacao as a
WHERE a.idCategoria = '$idcategoria' && a.idPessoa = '$idpessoa'
GROUP BY a.idPessoa AND a.idCategoria) as valorAvaliacao
FROM `tb_pessoa` as p
INNER JOIN tb_pessoacategoria as pc ON pc.idPessoa = p.idPessoa
INNER JOIN tb_foto as f ON pc.idPessoa = f.idPessoa and pc.idCategoria = f.idCategoria
INNER JOIN tb_categoria as c ON c.idCategoria = pc.idCategoria
WHERE c.idCategoria = '$idcategoria'
GROUP BY p.idPessoa
ORDER BY valorAvaliacao DESC, f.idFoto
Is there any way to do the same SELECT only without using the $idpessoa variable? I need you to have a column that shows the average reviews received, but without using INNER JOIN between tb_person and tb_review.
Why don’t you want to use the variable? How do I know if the user has just registered? If possible, it also leaves the structure of the bank because I believe it is necessary to improve this query.. must be very heavy processing..
– rLinhares
Because this select should list users, I do not have the person’s id, what I really need is a column that shows the average ratings of each user, if no one has voted should still appear 0, but do this without giving INNER JOIN between tb_person and tb_rating
– JeffNog
Then it would be nice to inform which values are being passed to the variables, which columns it needs, and better pass the table structures being used.
– Nicolas Sylverio
I edited and put together the comic book model
– JeffNog
Put some table data as text. Also put a desired output format
– Roberto de Campos