我们有3张桌子
表格票据
id | email
---+-----------------
1 | test@gmail.com
2 | test1@gmail.com
表客户
email | location
----------------+----------
test@gmail.com | Area1
test!@gmail.com | Area2
表区
location | zone
---------+--------
Area1 | South
Area2 | North
我正在尝试将查询输出为
Count(ticket.id) | Zone
-----------------+-----------
1 | South
1 | North
请给我一个很好的建议。提前谢谢!
答案 0 :(得分:0)
这是一个简单的join
group by
select count(ticket.id), Zone
from ticket
join customer on ticket.email=customer.email
join zone on customer.location=zone.location
group by zone