Chaitanya V
asked on
How to select random rows whose column sum meets the condition in Sql server
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 -
I want to get those random questions whose total sum of 'answerInSec' column 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.
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' column 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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Highly No. What exactly you wanted to achieve with this ?
I don't want to use Top is it possible with out that?How do you think will SQL server guess how many rows out of all in the table to return if you don't specify the number? In you example you used combination of 4, how would you do that without specifying that you need only 4 rows?
ASKER