Peewee generates an SQL query with syntax errors
Did you try this?

```python
mul = ((Listing.sale_price * Listing.yearly_rent)).cast('float')
avg = fn.avg(mul).alias('avg')
mul = mul.alias('mul')
``` Thank you; yes, this works!
But, I would expect peewee to implicitly turn off alias when used in irrelevant cases. To do this it would have to recursively inspect every sub-node in the tree... eg. a function call would have to recursively inspect each of it's arguments. Peewee doesn't do this to avoid overhead. The workaround I suggested is the best way to handle it.
I have the following query

```python
mul = ((Listing.sale_price * Listing.yearly_rent)).cast('float').alias('mul')
avg = fn.avg(mul).alias('avg')
Listing.select(avg, mul).group_by(mul).where(mul > 100)
```
Peewee generates an SQL query with syntax error on `sqlite3`.

```
peewee.OperationalError: near "AS": syntax error
```

```sql
SELECT avg(CAST(("t1"."sale_price" * "t1"."yearly_rent") AS float) AS "mul") AS "avg", CAST(("t1"."sale_price" * "t1"."sale_price") AS float) AS "mul"
FROM "listing" AS "t1"
WHERE ("mul" > 100) GROUP BY "mul"
```

I would expect the following correct query. Peewee should ignore the alias of a compound column when used on an aggregate function

```sql
SELECT avg(CAST(("t1"."sale_price" * "t1"."yearly_rent") AS float)) AS "avg", CAST(("t1"."sale_price" * "t1"."sale_price") AS float) AS "mul"
FROM "listing" AS "t1"
WHERE ("mul" > 100) GROUP BY "mul"
```