我在重新设计我的问题以便更清楚。我有几个(确切地说是5个)表,其中一个用户只能出现一次。我想列出每个用户出现的次数。
例子:
**employess table**
email | cn | more columns.. user@gr.com | name | etc
**intranet table**
email | data1 | more columns.. user@gr.com | something | etc
user1@gr.com | something | etc
user2@gr.com | something | etc
**sap table**
email | data1 | more columns..
user@gr.com | something | etc
user1@gr.com | something | etc
user2@gr.com | something | etc
**solman table**
email | data1 | more columns..
user@gr.com | something | etc
user1@gr.com | something | etc
user2@gr.com | something | etc
**orfeo table**
email | data1 | more columns..
user@gr.com | something | etc
user3@gr.com | something | etc
**saul table**
email | data1 | more columns..
user@gr.com | something | etc
user3@gr.com | something | etc
**EXPECTED RESULT**
email | Name | Total
user@gr.com | name user | 5 (this is the only user in all the 5 tables)
user1@gr.com | name user1 | 3
user2@gr.com | name user2 | 3
user3@gr.com | name user2 | 2
我尝试了左连接,但它只返回一个记录。不是名单。。。我做了什么´我做错了?
1条答案
按热度按时间xlpyo6sf1#
这种类型的查询需要使用
UNION ALL
: