测试数据(member ):
|----------------------| | id | pid | name | |----------------------| | 1 | 0 | judy | |----------------------| | 2 | 1 | judy | |----------------------| | 3 | 1 | jack | |----------------------| | 5 | 2 | tom | |----------------------| | 9 | 0 | jerry | |----------------------|
字段说明:
- id:用户id,int 自增
- pid:推荐人id,int not null default 0
- name:用户姓名,int not null default ”
要求:统计表中不重复的推荐人总数
SELECT
COUNT
(DISTINCT
pid) AS
total_referrers FROM
member WHERE
pid>0;