请找到以下数据库结构...
| id | account_number | referred_by |
+----+-----------------+--------------+
| 1 | ac203003 | ac203005 |
+----+-----------------+--------------+
| 2 | ac203004 | ac203005 |
+----+-----------------+--------------+
| 3 | ac203005 | ac203004 |
+----+-----------------+--------------+
我想达到以下结果...
id, account_number, total_referred
1, ac203005, 2
2, ac203003m 0
3, ac203004, 1
我正在使用以下查询...
SELECT id, account_number,
(SELECT count(*) FROM `member_tbl` WHERE referred_by = account_number) AS total_referred
FROM `member_tbl`
GROUP BY id, account_number
但它没有给出预期的结果,请帮忙。谢谢。