mardi 13 décembre 2016

How to select random rows whose column sum meets the condition in MySQL

Is it possible to select random rows from a table whose particular column total (sum) should be less than my condition value ?

My table structure is like -

id | question | answerInSec
1  | Quest1   | 15
2  | Quest2   | 20
3  | Quest3   | 10
4  | Quest4   | 15
5  | Quest5   | 10
6  | Quest6   | 15
7  | Quest7   | 20

I want to get those random questions whose total sum of 'answerInSec' is less than (nearest total) or equal to 60.

So random combination can be [1,2,3,4] OR [2,3,5,7] OR [4,5,6,7] etc.

Is this possible in single MySQL query ?




Aucun commentaire:

Enregistrer un commentaire