Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see something like this:</p> <p><img src="https://i.stack.imgur.com/m6YPR.png" alt="enter image description here"></p> <p><code>questions</code> is the list of questions to be answered. <code>question_type</code> is an enumeration that indicates what type of answer is expected (e.g. lookup from <code>question_choices</code>, a date, a number, text, etc.) - whatever types of data you expect to be entered. This, along with the other columns in this table, can drive your input form.</p> <p><code>question_answers</code> contains a list of predefined answers to questions (such as a predefined list of religions, or hair color, or eye color, etc.). This can be used to build a drop-down list of values on your input form.</p> <p><code>users</code> is pretty self explanatory.</p> <p><code>user_characteristics</code> contains a list of my answers to the questionnaire. The <code>weight</code> column indicates how important it is to me that someone looking for me have this same answer. The <code>question_choices_id</code> would be populated if the answer came from a select list built from the <code>question_choices</code> table. Otherwise <code>question_choices_id</code> would be NULL. The converse is true for the <code>value</code> column. <code>value</code> would be NULL if the answer came from a select list built from the <code>question_choices</code> table. Otherwise <code>value</code> would contain the user's hand crafted answer to the question.</p> <p><code>user_preferences</code> contains answers to the questionnaire for who I am looking for. The <code>weight</code> column indicates how important it is to me that the person I am looking for have this same answer. The <code>question_choices_id</code> and <code>value</code> columns behave the same as in the <code>user_characteristics</code> table.</p> <p>SQL to find my match might look something like:</p> <pre><code>SELECT uc.id ,SUM(up.weight) AS my_weighted_score_of_them ,SUM(uc.weight) AS their_weighted_score_of_me ,SUM(up.weight) + SUM(uc.weight) AS combined_weighted_score FROM user_preferences up JOIN user_characteristics uc ON uc.questions_id = up.questions_id AND uc.question_choices_id = up.question_choices_id AND uc.value = up.value AND uc.users_id != up.users_id WHERE up.users_id = me.id GROUP BY uc.id ORDER BY SUM(up.weight) + SUM(uc.weight) DESC ,SUM(up.weight) DESC ,SUM(uc.weight) DESC </code></pre> <p>For performance reasons, an index on user_characteristics(id, question_id, question_choices_id, value, and user_id) and an index on user_preferences(id, question_id, question_choices_id, value, and user_id) would be advisable.</p> <p>Note that the above SQL will return one row for EVERY user except the one making the request. This certainly is NOT desirable. Consequently, one might consider adding <code>HAVING SUM(up.weight) + SUM(uc.weight) &gt; :some_minimum_value</code> - or some other way to further filter the results.</p> <p>Further tweaks might include only returning people who value an answer as much or more than I do (i.e. their characteristic weight is >= my weight preference weight.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload