我有以下MySQL數據庫表:的CakePHP/PHP的MySQL的複雜查詢
cities
states
countries
與
members
samajs
(一羣人國際)
,我要創建我dashboard
網頁查詢,這將有如下結果:
Country Members Samajs Total (table header)
Country1 7 5 16 (country row with total members, samajs and total count)
state1 5 2 7 (state row with total members, samajs and total count)
city1 3 1 4 (all cities in that state, city row with total members, samajs and total count)
city2 2 0 2
state2 2 1 3
Country2 3 2 5 (country row with total members, samajs and total count)
...and vice versa....
這裏,members
表將有country_id, state_id and city_id
爲外鍵
samajs
表還會有country_id, state_id and city_id
作爲外鍵
任何想法,將會查詢什麼一樣的嗎?
謝謝!
感謝您的快速反應,它適用於國家,但我怎麼能修改它的狀態/城市組合?請讓我知道.. –
已編輯我的答案可以使用它 – Krishna
tnx但我不能管理所有的事情從單一查詢,如在cakephp這將是很難管理差異查詢所有 –