I have a Question table with the fields (QuestionID,QuestionMarks), and with the data fields look like –
QuestionID QuestionMarks
1 1
2 4
5 1
9 1
12 2
which means at the moment Question table has 5 Question of Total 9 marks, Now my problem is that i want to know that a combination of 4 Questions with 8 marks is possible and fetch out that combination ( in general a combination of “x” questions of “y” marks is possible) ?
I was thinking to use CTE, but was afraid that it will take lot of time to execute the query if i have tens of thousand question.
please suggest some idea how to get the data. I am using SQL Server version 2008
This is a start. It’s going to have poor performance:
Result set:
The tricky part is that the QPath value isn’t exactly the greatest way of storing ID values.