Skip to content

Instantly share code, notes, and snippets.

@qoega
Created January 10, 2020 12:21
Show Gist options
  • Save qoega/37ed223082e15670265c985a78e43f9f to your computer and use it in GitHub Desktop.
Save qoega/37ed223082e15670265c985a78e43f9f to your computer and use it in GitHub Desktop.
Open Issues ans Avg Open Issues Lifetime
SELECT
date,
avgIf(diff, created and not resolved) as avg_open_days,
countIf(created and not resolved) as cnt_open
FROM
(
SELECT
toDate( toString(y) || '-' || toString(m) || '-' || '01') as date,
dateDiff('day', created_at, date) as diff,
date >= created_at as created,
state,
closed_at,
state != 'open' and closed_at <= date as resolved
FROM
default.issues
CROSS JOIN
(
SELECT
arrayJoin(range(1,13,1)) as m,
arrayJoin(range(2016,2021,1)) as y
) t2
)
WHERE date < toDate('2020-02-01')
GROUP BY date
ORDER BY date ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment