I have been stuck on this for sometime now.
I have the following SQL Tables:
department
table
Id Name
1 DeptA
2 DeptB
3 DeptC
users
table
Id Name Dept
101 Alice 2
102 Bob 3
alpha
table
Id Uid Title
501 101 HELLO
502 102 HEY
503 101 SQL
beta
table
Id Uid Title
601 101 HELLO1
602 101 HEY1
603 102 SQL1
Explanation:
- There's basically a
users
table which has all the users. - Each user has a department (
Dept
field) - Each user has some records, linked to it with
Uid
, inalpha
andbeta
tables.
The result I want:
DeptA DeptB DeptC
0 4 2
I want the count of records in alpha
and beta
combined, grouped by Dept
of the users whose records are there in these tables.
Can someone help me with the SQL query?