我有以下兩個表:如何在MySQL SELECT結果集中包含自定義計數?
TABLE: area
*City_ID *Number Name
-------- ------- ----
SUR 1 Fleetwood
SUR 2 Whalley
SUR 3 Guildford
SUR 4 Newton
SUR 5 Cloverdale
SUR 6 South Surrey
ABB 1 Abbotsford East
ABB 2 Abbotsford West
ABB 3 Aberdeen
ABB 4 Bradner
ABB 5 Central Abbotsford
ABB 6 Matsqui
ABB 7 Poplar
ABB 8 Sumas Mountain
ABB 9 Sumas Prairie
TABLE: city
*ID Name
--- ----
SUR Surrey
ABB Abbotsford
LAN Langley
使用下面的語句:
SELECT DISTINCT area.City_ID, city.Name
FROM area
INNER JOIN city
WHERE area.City_ID = city.ID
我得到:
SELECT:
City_ID city.Name
------- ---------
SUR Surrey
ABB Abbotsford
但是我怎麼選擇以下內容:
SELECT:
City_ID city.Name area_COUNT
------- --------- ----------
SUR Surrey 6
ABB Abbotsford 9
其中area_COUNT
是area
中每行對應的行數City_ID
?
如果我可以,我會已經接受了這一點。等待8分鐘。 – 2012-07-17 08:53:43
請參閱回答評論[11519121](http://stackoverflow.com/questions/11518995/how-do-i-include-a-custom-count-in-a-mysql-select-result-set/11519121# 11519121)below – 2012-07-17 23:41:48