For a market research project, I have a table in a sqlite database that specifies the exact position of a question. For different sets of respondents, questions might be asked or not asked, or asked in different positions. The position is indicated by consecutive numbers for each group.
The requirement is to sort this table in a way that the same questions are grouped if the order allows it. In other words: If group1 is asked q1, q2 and then q3, and group2 is asked q3 first, then the first three rows should be show for group1 followed by the first row for group2.
Table:
group | question | position
g1 | q1 | 1
g1 | q2 | 2
g1 | q3 | 3
g1 | q4 | 4
g1 | q5 | 5
g1 | q8 | 6
g2 | q2 | 1
g2 | q3 | 2
g2 | q7 | 3
g2 | q8 | 4
g2 | q1 | 5
How it should look like sorted:
group | question | position
g1 | q1 | 1
g1 | q2 | 2
g2 | q2 | 1
g1 | q3 | 3
g2 | q3 | 2
g1 | q4 | 4
g1 | q5 | 5
g2 | q7 | 3
g1 | q8 | 4
g2 | q8 | 6
g2 | q1 | 5
I tried all kinds of sorts and groups, but can't solve the problem. Since the database is accessed through python, I could perform the sorting there, but I have a strong preference to pull already sorted data.
Aucun commentaire:
Enregistrer un commentaire