Return random strings from the best (i.e. 100 strings & # 8594; top 10 & # 8594; get 5 random numbers)

Situation: a table with a lot of photos, classified and with votes. I am doing this now:

SELECT n.nid, n.title, ....... order by v.value desc limit 0,5

I want to get a random result after sorting my lines by his votes. Now a table with hundreds of records gives me the top 5 rows. It’s always the same 5. It’s pretty repetitive, but of course 5 random lines will not be the best, since not all lines have a good quailty photo. Some may not be too good.

I do not want to just do this:

SELECT n.nid, ...... order by RAND() limit 0,5

I am looking for something like this:

SELECT n.nid, .....   order by RAND( v.value desc limit 0.10) limit 0,5

but, of course, this is not SQL :) Up to 50,000 rows are involved in the tables.

Thanks!

+3
1

? 10 , 5 . , .

: Lukáš

+1

Source: https://habr.com/ru/post/1721384/


All Articles