简体   繁体   English

mysql查询获取连接3个表的计数

[英]mysql query to get count joining 3 tables

We have 3 tables 我们有3张桌子

Table ticket 桌票

id | email
---+-----------------
1  | test@gmail.com
2  | test1@gmail.com

table customer 表客户

email           | location
----------------+----------
test@gmail.com  | Area1
test!@gmail.com | Area2

table zone 餐桌区

location | zone
---------+--------
Area1    | South
Area2    | North

I am trying to right query to output as 我正在尝试对查询进行输出

Count(ticket.id) | Zone
-----------------+-----------
 1               | South
 1               | North

Please give me a good suggestion. 请给我一个好的建议。 Thanks in advance! 提前致谢!

It is a simple join with group by 这是与group by的简单join

select count(ticket.id), Zone 
from ticket 
join customer on ticket.email=customer.email 
join zone on customer.location=zone.location
group by zone

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM