I have a DB schema something like this:
CREATE TABLE projects (project_id int);
CREATE TABLE project_members (user_id int, project_id int);
CREATE TABLE project_issues (issue_id int, project_id int);
What I want is to find all projects which have 10 or more members as well as 10 or more issues. I am struggling to come up with a query for this.
I want output something similar to:
project_id | members | issues
-----------+---------+-------
65 | 100 | 23
93 | 78 | 45
Preferably sorted by members then issues.
I have come up with:
SELECT projects.project_id, COUNT(project_members.user_id) FROM
project_members LEFT JOIN projects ON
project_members.project_id = projects.project_id GROUP BY projects
ORDER BY count;
but do not know how to take it to the next level in counting the issues as well.
I am using PostgreSQL 9.1