E
E
Evgeny Sheleg2011-03-29 20:23:20
PHP
Evgeny Sheleg, 2011-03-29 20:23:20

Top in several ways. PHP+MySQL

Hello. Please tell me how to make a Top in several parameters.
There is a basis in which the estimation contains. It is necessary to form a top not just by the maximum, but also taking into account how many people voted in total (number of entries). PHP+MySQL

Answer the question

In order to leave comments, you need to log in

7 answer(s)
E
ENargit, 2011-03-29
@ENargit

Look at the option used by Yandex for stores.
In your case, you can take Rq equal to, for example, 1.

B
bruteo, 2011-03-29
@bruteo

Calculate the average?
SELECT sum(rating/COUNT(*)) as avg FROM table GROUP BY element_id ORDER BY avg DESC LIMIT 10

E
Evgeny Sheleg, 2011-03-29
@Duti_Fruti

Either I didn't quite understand you, or you me.
Need:
To say a score of 4 (average) and the number of records 50, be higher than a score of 5 with 40 records.
To make it even clearer what it is for:
There is a vote for a book, the average score for a book is 4.3, a person came and put another book 5 (this is the first rating), so that it would not become higher than a book with 4.3 where 20 people voted.

N
nuclear, 2011-03-29
@nuclear

ORDER BY param1,param2?

D
Dzuba, 2011-03-29
@Dzuba

You can sort by several fields:

SELECT * FROM votes
GROUP BY item_id
ORDER BY COUNT(*) DESC, AVG(vote_value) DESC
LIMIT 10;

If this does not suit you, then please formulate the essence of the relationship between the rating and the number of votes.

A
Anton Pronin, 2011-03-29
@nightw0rk

Look, there are 3 books, the 1st 20 votes 4.3 average, the 2nd 4 votes 4.8 average, and the 3rd 30 votes average 4.2
do the calculation
Number of goals / avg. score
1. 20/4.3=4.6
2. 4/4.8=0.8
3. 30/4.2=7.14
sort
1. place 3 book
2. place 1 book
3. place 2 book
Example:
table "book"
id| name | id_mark|
table "mark"
id_mark| mark sql maybe it all depends on the db architecture
select b.name,((select (count(mark)/(sum(mark)/count(mark))) from mark m where m.id_mark=b.id_mark)) as mVal from book b order by mVal DESC;

E
Evgeny Sheleg, 2011-03-29
@Duti_Fruti

gaelpa, I'm asking for help in implementing the most correct top. How and what I do not know. He only stated the essence that there are books, voices and the number of votes. Interested in how you would do it or how it should be done.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question