# View: restrictions_aggregated_subaccount_territory_snowflake

**View Name:** restrictions_aggregated_subaccount_territory_snowflake
**Table Source:** `Derived from: Art_Relations_Prod_Art_Relations.Country, Art_Relations_Prod_Art_Relations.Subaccount, Art_Relations_Prod_Art_Relations.Subaccount_Territory_Restriction, Dbt_Prod.Active_Vendor_Contracts, Intelligence.Dbt_Prod + 3 more`
**File Path:** `restrictions_aggregated_subaccount_territory_snowflake.view.lkml`

## Overview

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

## Dimensions

| Name | Type |
|------|------|
| `subaccount_id` | number |
| `name` | string |

## Measures

| Name | Type |
|------|------|
| `count_aggregate_restrictions` | count_distinct |
| `list_aggregate_restrictions` | string |

## Derived Table

```sql
sql:
SELECT agg_restrictions.subaccount_id, c.name
FROM (
    SELECT sa.subaccount_id, vtr.country_id
    FROM orchard_app_reporting_v2.art_relations_prod_art_relations.subaccount sa
        INNER JOIN intelligence.dbt_prod.active_vendor_contracts vw ON sa.vendor_id = vw.vendor_id
        INNER JOIN (
            SELECT id, TRY_TO_NUMBER(a.value::string) AS country_id
            FROM royalty_accounting_reporting.prod.vw_dim_abacus_ar_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 subaccount_id, country_id
        FROM orchard_app_reporting_v2.art_relations_prod_art_relations.subaccount_territory_restriction
) agg_restrictions
    INNER JOIN orchard_app_reporting_v2.art_relations_prod_art_relations.country c ON agg_restrictions.country_id = c.id ;;
```

