Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从表中获取计数的mysql查询_Mysql - Fatal编程技术网

从表中获取计数的mysql查询

从表中获取计数的mysql查询,mysql,Mysql,我有3张这样的桌子: Areas id city_id area 1 1 mayfield 2 2 cleveland neighbourhood id neighbourhood area_id 101 cayahoga 1 102 milan 1 103 downtown 2 Salons id

我有3张这样的桌子:

Areas 
id      city_id         area
1       1               mayfield
2       2               cleveland

neighbourhood
id      neighbourhood   area_id
101     cayahoga        1
102     milan           1
103     downtown        2

Salons
id      neighbourhood_id
3       101
4       101
5       102
我正在努力统计所有地区的所有沙龙

类似于区域内的沙龙(梅菲尔德=2,克利夫兰=1)


是否可以在1个查询中执行此操作

不给计数像:梅菲尔德2,克利夫兰1。它只是给count=3?不知道为什么那不起作用。我刚把它改成“count(s.id)”。。。现在应该可以工作了。。。
select area,count(s.id) as salon_count FROM
Areas a
INNER JOIN neighbourhood n
ON a.id = n.area_id
INNER JOIN
Salons s on s.neigbourhood_id = n.id
GROUP BY area
SELECT areas.area,COUNT(Salons.id)
FROM areas
LEFT JOIN neighbourhood ON neighbourhood.area_id = areas.id
LEFT JOIN Salons ON Salons.neighbourhood_id = neighbourhood.id
GROUP BY areas.id