邀请注册,sql语句不知道如何写了,

WBOY
Release: 2016-06-13 13:00:48
Original
1198 people have browsed it

邀请注册,sql语句不知道怎么写了,求助!!!!
数据库为mysql,数据表A中有四个字段,分别为 id,name,password,pid

id为自动增长的主键。

pid为注册时邀请人的id,默认为0

四条数据

id    name    password    pid
1     test     121121     0
2     test2    212121     1
3     test3     415454    1
4     test4    1212121    3

我怎么能用sql语句显示出谁邀请了谁? 邀请了几个人?
------解决方案--------------------
未测试, 自己调整或再问

select u.id, count(ui.id), group_concat(ui.id)
from users u 
   join users ui  
     on u.id=ui.pid
group by u.id
;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!