I have a query that I'm trying to build the logic for as a derived view. Basically, translating my view that is on a DB to Denodo as a Derived View. Trying to figure out that if we have a subquery in the **from** or where **clause**, do we have to create another Derived view of this subquery, and then our final derived view will use this new other derived view as a source?
Here are a couple examples of view logic similar to what I'm talking about:
**Example A**
```
SELECT SP.TerritoryID,
SP.BusinessEntityID,
SP.Bonus,
TerritorySummary.AverageBonus
FROM (SELECT TerritoryID,
AVG(Bonus) AS AverageBonus
FROM Sales.SalesPerson
GROUP BY TerritoryID) AS TerritorySummary
INNER JOIN
Sales.SalesPerson AS SP
ON SP.TerritoryID = TerritorySummary.TerritoryID
```
**Example B**
```
SELECT
a.col1,
a.col2,
SUM (col3) "COL3",
SUM (col4) "COL4",
SUM (col4) "COL5"
FROM schema_one.table_a a,
(SELECT DISTINCT col1, col2
FROM schema_two.table_b) b
WHERE a.col1 = b.col1 AND a.col2 = b.col2
GROUP BY a.col1, a.col2;
```
I am assuming that in Example A above, that I would need to build a derived view based off of the code below and then use this as a source to build my target/final view?
(SELECT TerritoryID,
AVG(Bonus) AS AverageBonus
FROM Sales.SalesPerson
GROUP BY TerritoryID) AS TerritorySummary
INNER JOIN
Sales.SalesPerson AS SP
ON SP.TerritoryID = TerritorySummary.TerritoryID