Answer the question
In order to leave comments, you need to log in
MySQL fetch, count number?
Hello.
Users have reviews, all of them have different ratings from 1 to 5 (bad and excellent, respectively).
Tell me how to economically calculate their number, you need to find out how many reviews with a rating of 1, 2, etc. For the selected user.
Is it possible to do this in one request? And How?
Thanks in advance c:
Answer the question
In order to leave comments, you need to log in
select
user_id,
otziv_id,
SUM(CASE WHEN ocenka = 1 THEN 1 ELSE 0 END) ocenka_1,
SUM(CASE WHEN ocenka = 2 THEN 1 ELSE 0 END) ocenka_2,
SUM(CASE WHEN ocenka = 3 THEN 1 ELSE 0 END) ocenka_3,
....
from otziv_table
group by user_id, otziv_id
having user_id = #####
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question