We have a table (called QuestionBank) on which each question is stored:
Id Topic Hardness Position 4 1 3 4 5 1 2 1 6 1 1 2 7 1 3 3 8 1 3 4 9 2 2 1 10 2 2 2 11 2 3 3 12 3 1 1 13 3 1 1 14 3 1 2
Each question relates to a topic and has its own firmness and position (each similar question, based on their content, has the same position on the corresponding topic).
Note that the value in the Position column does not make sense, and it simply shares similar questions in the subject.
The goal is to select N records with X-records Harness = 1 and Y Hardness = 2 and Z-records Hardness = 3, etc. randomly; with this limitation that as far as possible there are no entries with a similar topic and position returned in the result set.
For example, entries with Id = 4 and Id = 8 are similar in any topic and position, so one of them should be in the result set.
source share