我们有3张桌子

桌票

id | email
---+-----------------
1  | [email protected]
2  | [email protected]


表客户

email           | location
----------------+----------
[email protected]  | Area1
[email protected] | Area2


餐桌区

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


我正在尝试对查询进行正确输出

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


请给我一个好的建议。提前致谢!

最佳答案

这是带有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

关于php - mysql查询获取连接3个表的计数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32368733/

10-13 04:45