# union query reply number
The code is as follows |
Copy Code |
SELECT ask.id, Count (answer.father_id), Ask.answer_num From ' Table name _ask ' as Ask Left JOIN ' table name _answer ' as answer on ask.id = answer.father_id GROUP by answer.father_id ORDER BY Ask.id ASC |
# Modify City ID
The code is as follows |
Copy Code |
UPDATE table name _ask SET Cityid = ( SELECT Cityid From table name WHERE table name _ask.borough_id = table name. ID Order by ID ASC LIMIT 0, 1 ) |
# Modify back to plural
The code is as follows |
Copy Code |
UPDATE table name _ask SET answer_num = ( SELECT count (table name _answer.father_id) From ' Table name _answer ' where table name _ask.id = table name _answer.father_id GROUP by table name _answer.father_id Order BY table name _ask.id ASC LIMIT 0, 1 ) At last |
Build justice, if it's possible, we'd better separate the SQL to handle this. Oh, this site original article to be cut must indicate the source http://www.111cn.net