Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH
- tested_issues AS (
- SELECT
- iss.id AS issue_id,
- iss.closed_on,
- iss.project_id
- FROM issues iss
- LEFT JOIN projects p ON p.id = iss.project_id
- WHERE
- $__timeFilter(iss.closed_on)
- AND iss.tracker_id in (83, 85) -- трекер DevTask или Bug
- AND iss.status_id IN (4) -- задача завершена
- AND p.lft >= (SELECT lft FROM projects WHERE id = 4) -- проект внутри w1
- AND p.rgt <= (SELECT rgt FROM projects WHERE id = 4)
- ),
- issues_assigned_changes AS (
- SELECT
- j.journalized_id AS issue_id,
- j.created_on AS event_on,
- jd.value AS assigned_to_id,
- ROW_NUMBER() OVER (PARTITION BY j.journalized_id ORDER BY j.created_on) AS rnk
- FROM journal_details jd
- INNER JOIN journals j ON j.id = jd.journal_id
- WHERE
- j.journalized_id IN (SELECT issue_id FROM tested_issues)
- AND j.journalized_type = 'Issue'
- AND jd.prop_key = 'assigned_to_id'
- ),
- issues_assigned_periods AS (
- SELECT
- s.issue_id,
- s.event_on AS started_at,
- COALESCE(f.event_on, NOW()) AS finished_at,
- s.assigned_to_id
- FROM issues_assigned_changes s
- LEFT JOIN issues_assigned_changes f ON f.issue_id = s.issue_id AND f.rnk = s.rnk + 1
- ),
- result AS (
- SELECT
- m.month AS mmonth,
- iss.issue_id AS quantity_tasks,
- -- QA Нагишева, Романова, Тюренкова и Сухорукова
- COUNT(
- CASE WHEN
- jd.old_value IN (41, 87, 103)
- AND jd.value IN (70, 15, 72, 88)
- AND u.id IN (1478, 1536, 2306, 2433)
- THEN j.id
- ELSE NULL
- END
- ) AS cnt_qa,
- -- старый статус "Внутреннее тестирование", "Тестирование на препроде", “Тестирование на проде”, новый статус "Запланировано", "Готово", "Перенести на препрод", “Перенести на прод”
- COUNT(
- CASE WHEN
- jd.old_value IN (41, 87, 103)
- AND jd.value IN (70, 15, 72, 88)
- AND u.id NOT IN (1478, 1536, 2306, 2433)
- AND iap.assigned_to_id != u.id
- THEN j.id
- ELSE NULL
- END
- ) AS cnt_dev,
- COUNT(
- CASE WHEN
- jd.old_value IN (41, 87, 103)
- AND jd.value IN (70, 15, 72, 88)
- AND u.id NOT IN (1478, 1536, 2306, 2433)
- AND iap.assigned_to_id = u.id
- THEN j.id
- ELSE NULL
- END
- ) AS cnt_self
- FROM nag_monthes m
- LEFT JOIN tested_issues iss ON DATE_FORMAT(iss.closed_on, '%Y-%m-01') = DATE_FORMAT(m.month, '%Y-%m-01')
- LEFT JOIN projects p ON p.id = iss.project_id
- LEFT JOIN journals j ON j.journalized_id = iss.issue_id AND j.journalized_type = 'Issue'
- LEFT JOIN journal_details jd ON jd.journal_id = j.id AND jd.prop_key = 'status_id'
- LEFT JOIN users u ON u.id = j.user_id
- LEFT JOIN issues_assigned_periods iap ON
- iap.issue_id = iss.issue_id
- AND iap.assigned_to_id IS NOT NULL
- AND iap.started_at <= j.created_on
- AND iap.finished_at >= j.created_on
- WHERE
- $__timeFilter(m.month)
- GROUP BY 1, iss.issue_id
- ORDER BY 1
- )
- SELECT
- t.mmonth,
- COUNT(DISTINCT CASE WHEN t.cnt_qa > 0 AND t.cnt_dev = 0 AND t.cnt_self = 0 THEN t.quantity_tasks END) AS "не Dev",
- COUNT(DISTINCT CASE WHEN t.cnt_dev > 0 THEN t.quantity_tasks END) AS "Dev",
- COUNT(DISTINCT CASE WHEN t.cnt_self > 0 THEN t.quantity_tasks END) AS "Self"
- FROM result t
- GROUP BY 1
- ORDER BY 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement