select from multiple subqueries
Your code is completely unreadable. Please reduce to a minimal, clear example if you think there is a bug.

However this does not seem like a bug report, but rather like a question. In that case, the proper place to post is StackOverflow or you can try asking in the IRC channel (peewee on freenode), or on the mailing list.

A hint is that you should probably use `from_()` to list your multiple query sources. Or refactor to use common table expressions. There are some examples that may help, here:

http://docs.peewee-orm.com/en/latest/peewee/query_examples.html#joins-and-subqueries Ok, what about this:

```
Select q1.name,q1.countA,q2.countB
FROM
(select name, count()countA )q1,
(select name, count()countB )q2
```

How to combine 2 subqueries into 1? ```python

q1 = Foo.select(Foo.name, fn.COUNT(Foo.bar))
q2 = Foo.select(Foo.name, fn.COUNT(Foo.baz).alias('count'))

query = Foo.select(q1.c.name, q2.c.name, q2.c.count).from_(q1, q2)
```

Untested, but that's the jist of it. Thanks, this helped.
Hi, trying to combine multiple subqueries into one, but can't see any guide for this, can you advise please.

 ```
SELECT q5.grpby,
    q5.cat AS category,
    q5.sumallmonths AS total,
    q4.avg12month AS avg12mnt,
   FROM ( 
	   SELECT tag_list."groupName" AS cat,
            tag_list."tagGroup" AS grpby,
            sum(transactions.trans_amnt) AS sumallmonths
           FROM tag_list
             LEFT JOIN transactions ON transactions.trans_cat = tag_list.id
          GROUP BY tag_list."tagGroup", tag_list."groupName"
   ) q5,
    ( SELECT tag_list."groupName" AS cat,
            round(sum(transactions.trans_amnt) / 12::numeric, 2) AS avg12month
           FROM tag_list
             LEFT JOIN transactions ON transactions.trans_cat = tag_list.id 
		AND transactions.trans_date >= date_trunc('month'::text, now()::date - '1 year'::interval) 
		AND transactions.trans_date <= (date_trunc('month'::text, now())::date - 1)
          GROUP BY tag_list."groupName"
		  ) q4
  WHERE q4.cat::text = q5.cat::text
  ORDER BY q5.grpby;
```

and my peewee attempt:
```

	def get_statistics(self):
		q5=tag_list.select(
tag_list.groupName.alias('tag')
,tag_list.tagGroup.alias('grpBy')
,fn.SUM(transactions.trans_amnt).alias('sumAllMonths'))
.join(transactions, on=(transactions.trans_cat == tag_list.id)).group_by(tag_list.tagGroup,tag_list.groupName)).order_by(tag_list.tagGroup)
		
q4=(tag_list.select(
tag_list.groupName.alias('tag')
,tag_list.tagGroup.alias('grpBy')
,fn.SUM(transactions.trans_amnt).alias('avg12Months'))
.join(transactions, on=(transactions.trans_cat == tag_list.id)).where(transactions.trans_date.between(first12MonthsAgo,lastOfPrevMonth)).group_by(tag_list.tagGroup,tag_list.groupName)).order_by(tag_list.tagGroup)

		query = q4 & q5
		return query
```

the webpage doesn't throw any error, and no results