US #1080 » script batch de rattrapage report_authorization.sql
| 1 |
use salarymarket; |
|---|---|
| 2 |
INSERT INTO company_reports_authorization (companyId, report_generated, report_authorized) |
| 3 |
SELECT
|
| 4 |
c.id AS companyId, |
| 5 |
COUNT(cr.id) AS report_generated, |
| 6 |
CASE
|
| 7 |
WHEN c.subscription_type = 'Advanced' THEN 'Illimited' |
| 8 |
ELSE '1' |
| 9 |
END AS report_authorized |
| 10 |
FROM company c |
| 11 |
LEFT JOIN company_reports cr ON cr.companyId = c.id |
| 12 |
WHERE c.id NOT IN ( |
| 13 |
SELECT companyId FROM company_reports_authorization |
| 14 |
)
|
| 15 |
GROUP BY c.id, c.subscription_type; |