# View: int_prod_vw_restrictions_release_territory_codes

**View Name:** int_prod_vw_restrictions_release_territory_codes
**Table Source:** `Derived from: Art_Relations_Prod_Art_Relations.Artist_Info, Art_Relations_Prod_Art_Relations.Country, Art_Relations_Prod_Art_Relations.Release_Territory_Restriction, Art_Relations_Prod_Art_Relations.Releases, Art_Relations_Prod_Art_Relations.Subaccount_Territory_Restriction + 3 more`
**File Path:** `int_prod_vw_restrictions_release_territory_codes.view.lkml`

## Overview

- **File Size:** 2034 bytes
- **Lines of Code:** 47
- **Dimensions:** 2
- **Measures:** 0
- **Dimension Groups:** 0
- **Filters:** 0

## Dimensions

| Name | Type |
|------|------|
| `release_id` | number |
| `list_aggregate_restrictions` | string |

## Derived Table

```sql
sql:
    WITH release_territory_restrictions AS (SELECT agg_restrictions.release_id, c.country_code as country_code
   FROM (
       SELECT r.release_id, vtr.country_id
       FROM orchard_app_reporting_v2.art_relations_prod_art_relations.releases r
           INNER JOIN orchard_app_reporting_v2.art_relations_prod_art_relations.artist_info ai ON r.artist_id = ai.artist_id
           INNER JOIN intelligence.dbt_prod.active_vendor_contracts vw ON ai.vendor_id = vw.vendor_id
           INNER JOIN (
               SELECT id, TRY_TO_NUMBER(a.value::string) AS country_id
               FROM orchard_app_reporting_v2.art_relations_prod_art_relations.vendor_contract,
               LATERAL FLATTEN(INPUT => SPLIT(territory_carve_out, ',')) a) vtr ON vtr.id = vw.vendor_contract_id
       WHERE vtr.country_id IS NOT NULL
       UNION ALL
           SELECT r.release_id, str.country_id
           FROM orchard_app_reporting_v2.art_relations_prod_art_relations.releases r
               INNER JOIN orchard_app_reporting_v2.art_relations_prod_art_relations.subaccount_territory_restriction str ON r.subaccount_id = str.subaccount_id
           WHERE r.subaccount_id IS NOT NULL
       UNION ALL
           SELECT release_id, country_id
           FROM orchard_app_reporting_v2.art_relations_prod_art_relations.release_territory_restriction
   ) agg_restrictions
       INNER JOIN orchard_app_reporting_v2.art_relations_prod_art_relations.country c ON agg_restrictions.country_id = c.id)

SELECT
  release_id,
  LISTAGG(DISTINCT country_code, '; ') WITHIN GROUP (ORDER BY country_code) AS list_aggregate_restrictions
FROM release_territory_restrictions
GROUP BY 1 ;;
```

