view raw
Burak Topal Burak Topal - 10 months ago 39
SQL Question

SQL find ID by Sum of rates

Hey cant find the right answer for my question.
if have a table :

DB :rate

1 id int(11)
2 type varchar(256)
3 candidate_id int(11)
4 data text(rating data is inside here 1-10)

I wannt all Candidate_ids as result where the avarage rate is a search string for example 3. How can i get this happen i tryed it but cant get it my own.

Every candidate has more than 5 Records in the DB:rate

id type candidate_id data

1 vote 5 10

2 vote 5 4

3 vote 4 4

4 vote 4 3

5 vote 5 8


Assuming I understand the question, I think you are looking for something like this:

SELECT candidate_id   
FROM TableName
GROUP BY candidate_id   
HAVING AVG(data) = 3