I have 4 tables, MASTER, TRANS1, TRANS2
and TRANS3
. I want to get count by USERID
in table MASTER
from tables TRANS1-3
.
This show tables for references.
Master table:
USERID REF
--------------------
1 Alfa
2 Beta
3 Charlie
4 Delta
5 Echo
TRANS1 table
Id USERID
------------
1 1
2 1
3 2
4 3
5 5
TRANS2 table
Id USERID
------------
1 2
2 3
3 4
4 5
I want to return to another table or view like this
USERID COUNT_FROM_TRANS1 COUNT_FROM_TRANS2 COUNT_FROM_TRANS3
--------------------------------------------------------------------
1 2 0 1
2 1 1 2
3 1 1 3
4 0 1 4
5 1 5 5
How does this work with SQL Server 2014?