ASdzxf

Untitled

Jun 23rd, 2021
675
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select surveys_surveyarea.name, COUNT(surveys_survey.id)
  2. from surveys_survey
  3. JOIN surveys_surveyarea ON surveys_survey.area_id = surveys_surveyarea.id
  4. GROUP BY surveys_surveyarea.name;
  5.  
  6.  
  7. select surveys_surveyarea.name, surveys_survey.name, COUNT(question_id)
  8. from surveys_surveyquestion
  9. JOIN surveys_survey ON surveys_surveyquestion.survey_id = surveys_survey.id
  10. JOIN surveys_surveyarea ON surveys_survey.area_id = surveys_surveyarea.id
  11. GROUP BY surveys_surveyarea.name, surveys_survey.name
  12. ORDER BY surveys_surveyarea.name, surveys_survey.name
  13.  
  14.  
  15. select surveys_surveyarea.name, surveys_survey.name, surveys_question.content
  16. from surveys_surveyquestion
  17. JOIN surveys_survey ON surveys_surveyquestion.survey_id = surveys_survey.id
  18. JOIN surveys_surveyarea ON surveys_survey.area_id = surveys_surveyarea.id
  19. JOIN surveys_question ON surveys_surveyquestion.question_id = surveys_question.id
  20. ORDER BY surveys_surveyarea.name, surveys_survey.name
  21.  
  22. select surveys_surveyarea.name, surveys_survey.name, surveys_question.content, surveys_answer.content
  23. from surveys_surveyquestion
  24. JOIN surveys_survey ON surveys_surveyquestion.survey_id = surveys_survey.id
  25. JOIN surveys_surveyarea ON surveys_survey.area_id = surveys_surveyarea.id
  26. JOIN surveys_question ON surveys_surveyquestion.question_id = surveys_question.id
  27. LEFT JOIN surveys_answer ON surveys_question.correct_answer_id = surveys_answer.id
  28. ORDER BY surveys_surveyarea.name, surveys_survey.name
  29.  
  30.  
  31. select auth_user.id, username
  32. from auth_user
  33. WHERE auth_user.id IN (
  34.     SELECT author_id
  35.     FROM surveys_survey
  36. )
  37.  
  38. select distinct auth_user.id, username
  39. from auth_user
  40. RIGHT JOIN surveys_survey ON surveys_survey.author_id = auth_user.id
  41. ORDER BY username
  42.  
  43. select username, MIN(DATE(surveys_completesurvey.completed_at) - DATE(auth_user.date_joined)) as date_completed
  44. from auth_user
  45. join surveys_completesurvey ON auth_user.id = surveys_completesurvey.user_id
  46. GROUP BY username
  47. ORDER BY date_completed DESC
RAW Paste Data