Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. select distinct gyms_topics.gym_id as gym_id,
  2. question_history_data.uuid,
  3. question_history_data.knowledge_points_acquired,
  4. question.score_points,
  5. question_history_data.last_date
  6. from learning.question question
  7. join learning.topic topic on topic.id = question.topic_id
  8. join learning.gyms_topics gyms_topics
  9. on gyms_topics.topic_id = topic.id
  10. left join
  11. (select question_last_answer.uuid, question_last_answer.last_date, question_last_answer.knowledge_points_acquired, question_last_answer.topic_id_2
  12. from learning.question question_with_history
  13. join (select question.uuid, max(answer_history.end_date) as last_date,topic_id_result.topic_id as topic_id_2,answer_history.knowledge_points_acquired
  14. from learning.question question
  15. join learning.answer_history answer_history
  16. on answer_history.question_id = question.id
  17. join
  18. (SELECT distinct topic.id as topic_id
  19. from learning.gyms_topics gyms_topics
  20. left join learning.topic topic on topic.id = gyms_topics.topic_id
  21. where (topic.parent_id is not null or topic.id not in
  22. (select topic.id
  23. from learning.topic topic
  24. left join learning.topic subtopic on subtopic.parent_id = topic.id
  25. left join learning.gyms_topics gyms_topics on gyms_topics.topic_id = topic.id
  26. where gyms_topics.gym_id in (:gymIds)
  27. group by topic.id
  28. having count(subtopic.id) > 0)
  29. )
  30. and topic.status in (:topicStatuses)
  31. and gyms_topics.gym_id in (:gymIds)) as topic_id_result on question.topic_id = topic_id_result.topic_id
  32. where answer_history.account_id = :accountId
  33. and answer_history.state in (:historyStates)
  34. and answer_history.end_date >= :forgettingDate
  35. group by question.uuid, topic_id_2,knowledge_points_acquired) as question_last_answer
  36. on question_with_history.uuid = question_last_answer.uuid
  37. ) as question_history_data on question_history_data.uuid = question.uuid
  38. where question.topic_id = question_history_data.topic_id_2
  39. and question.status in (:questionStatuses)
  40. and gyms_topics.gym_id in (:gymIds) order by question_history_data.uuid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement