Skip to content

Les licences B2C dupliquées sans l'original

Permet d'identifier des licences dupliquées à supprimer

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
WITH duplicated_ol AS (
    SELECT license.*, FIRST(license.id, license.starts_at) AS license_id_to_keep
    FROM organization_license AS license
    WHERE license.organization_id = 399
        AND (license.ends_at IS NULL OR license.ends_at > NOW())
    GROUP BY license.user_id, license.plan_id, DATE(license.starts_at)
    HAVING COUNT(*) > 1
)
SELECT organization_license.*
FROM organization_license
    JOIN duplicated_ol ON duplicated_ol.id = organization_license.id
        AND duplicated_ol.license_id_to_keep != organization_license.id;

Keywords

organization_license B2C duplicated