Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- | EMPLOYEE | QUESTION_ID | QUESTION_TEXT | OPTION_ID | OPTION_TEXT |
- |----------|-------------|------------------------|-----------|--------------|
- | Bob | 1 | Do you like soup? | 1 | Yes |
- | Alex | 1 | Do you like soup? | 1 | Yes |
- | Kate | 1 | Do you like soup? | 3 | I don't know |
- | Bob | 2 | Do you like ice cream? | 1 | Yes |
- | Alex | 2 | Do you like ice cream? | 3 | I don't know |
- | Oliver | 2 | Do you like ice cream? | 1 | Yes |
- | Bob | 3 | Do you like summer? | 2 | No |
- | Alex | 3 | Do you like summer? | 1 | Yes |
- | Jack | 3 | Do you like summer? | 2 | No |
- | Bob | 4 | Do you like winter? | 3 | I don't know |
- | Alex | 4 | Do you like winter? | 1 | Yes |
- | Oliver | 4 | Do you like winter? | 3 | I don't know |
- | EMPLOYEE | CALC |
- |----------|------|
- | Bob | 2 |
- | Alex | 2 |
- | Kate | 1 |
- | Jack | 1 |
- | Oliver | 2 |
- CALC = A + B;
- A - If a user answered to first and/or second question then the value should be 1, otherwise 0.
- B - If a user answered to third and/or fourth question then the value should be 1, otherwise 0.
- select
- employee,
- (
- case when count(question_id = 1) or count(question_id = 2) > 0 then 1 else 0 end
- +
- case when count(question_id = 3) or count(question_id = 4) > 0 then 1 else 0 end
- ) as calc
- from
- answers
- group by
- employee
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement