Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. | EMPLOYEE | QUESTION_ID | QUESTION_TEXT | OPTION_ID | OPTION_TEXT |
  2. |----------|-------------|------------------------|-----------|--------------|
  3. | Bob | 1 | Do you like soup? | 1 | Yes |
  4. | Alex | 1 | Do you like soup? | 1 | Yes |
  5. | Kate | 1 | Do you like soup? | 3 | I don't know |
  6. | Bob | 2 | Do you like ice cream? | 1 | Yes |
  7. | Alex | 2 | Do you like ice cream? | 3 | I don't know |
  8. | Oliver | 2 | Do you like ice cream? | 1 | Yes |
  9. | Bob | 3 | Do you like summer? | 2 | No |
  10. | Alex | 3 | Do you like summer? | 1 | Yes |
  11. | Jack | 3 | Do you like summer? | 2 | No |
  12. | Bob | 4 | Do you like winter? | 3 | I don't know |
  13. | Alex | 4 | Do you like winter? | 1 | Yes |
  14. | Oliver | 4 | Do you like winter? | 3 | I don't know |
  15.  
  16. | EMPLOYEE | CALC |
  17. |----------|------|
  18. | Bob | 2 |
  19. | Alex | 2 |
  20. | Kate | 1 |
  21. | Jack | 1 |
  22. | Oliver | 2 |
  23.  
  24. CALC = A + B;
  25.  
  26. A - If a user answered to first and/or second question then the value should be 1, otherwise 0.
  27. B - If a user answered to third and/or fourth question then the value should be 1, otherwise 0.
  28.  
  29. select
  30. employee,
  31. (
  32. case when count(question_id = 1) or count(question_id = 2) > 0 then 1 else 0 end
  33. +
  34. case when count(question_id = 3) or count(question_id = 4) > 0 then 1 else 0 end
  35. ) as calc
  36. from
  37. answers
  38. group by
  39. employee
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement