Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. CREATE OR REPLACE VIEW study.timelinesVsSites
  2. AS
  3. SELECT
  4. t_line.timelineID
  5. ,site.siteID
  6. ,t_line.timelineName
  7. ,t_line.timelineNotes
  8. ,tline_v_site.isDeactivated
  9. ,t_line_stage.timelineStageID
  10. ,t_line_stage.stageName
  11. ,t_line_stage.stagePredecessorID
  12. ,predecessor.stageName AS predecessorName
  13. ,t_line_stage.timelineStageNotes
  14. FROM study.timeline AS t_line
  15. -- This has to be a left join as potentially someone might create a timeline
  16. -- but not assign a stage to it which would cause this join to not return timelines.
  17. LEFT JOIN study.timelineStage AS t_line_stage
  18. ON t_line.timelineID = t_line_stage.timelineID
  19. INNER JOIN study.timelineVsSite AS tline_v_site
  20. ON tline_v_site.timelineID = t_line.timelineID
  21. -- join table on itself to get predecessor stage names.
  22. LEFT JOIN study.timelineStage AS predecessor
  23. ON t_line_stage.stagePredecessorID = predecessor.stagePredecessorID
  24. -- join on customer.site to translate siteID = 0 into all known sites
  25. LEFT JOIN customer.site
  26. ON site.siteID = if(tline_v_site.siteID = 0, site.siteID, tline_v_site.siteID)
  27. ORDER BY timelineID, SiteID, timelineStageID;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement