# 聯合查詢回復數
代碼如下 復制代碼SELECT ask.id, count( answer.father_id ) , ask.answer_num
FROM `表名_ask` AS ask
LEFT JOIN `表名_answer` AS answer ON ask.id = answer.father_id
GROUP BY answer.father_id
ORDER BY ask.id ASC
# 修改城市ID
代碼如下 復制代碼UPDATE 表名_ask SET cityid =
(
SELECT cityid
FROM 表名
WHERE 表名_ask.borough_id = 表名.id
ORDER BY id ASC LIMIT 0, 1
)
# 修改 回復數
UPDATE 表名_ask SET answer_num =
(
SELECT count( 表名_answer.father_id )
FROM `表名_answer`
where 表名_ask.id = 表名_answer.father_id
GROUP BY 表名_answer.father_id
ORDER BY 表名_ask.id ASC
LIMIT 0 , 1
)
最後
建義一下如果有可能我們還是把sql分開來處理這樣會更好一些哦,本站原創文章轉截必須注明來源http://www.111cn.net