Skip to content

Instantly share code, notes, and snippets.

@bstancil
Created July 23, 2015 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bstancil/554c0f5de49d046ce70b to your computer and use it in GitHub Desktop.
Save bstancil/554c0f5de49d046ce70b to your computer and use it in GitHub Desktop.
snippets.sql
SIMPLE VERSION
## Snippet
SELECT rr.id,
rr.created_at,
rr.report_id,
rr.account_id,
rr.executed_by_id,
rr.data_source_id,
rr.state,
MAX(CASE WHEN rs.id IS NOT NULL OR lsr.id IS NOT NULL THEN 1 ELSE 0 END) AS scheduled_run
FROM report_runs rr
LEFT JOIN report_schedule_runs rs
ON rs.report_run_id = rr.id
LEFT JOIN list_run_report_runs lrrr
ON lrrr.report_run_id = rr.id
LEFT JOIN list_schedule_runs lsr
ON lsr.list_run_id = lrrr.list_run_id
GROUP BY 1,2,3,4,5,6,7
## Query
SELECT *
FROM ({{run_detail}}) a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment