Invitation registration, SQL statements do not know how to write,

Source: Internet
Author: User
Invitation to register. I don't know how to write the SQL statement. for help !!!! The database is mysql, and Data Table A has four fields: & nbsp; id, name, password, and pidid. Pid is the id of the invitee at the time of registration. the default value is 0. four data IDs & nbsp; name invite registration. you do not know how to write the SQL statement, help !!!!
The database is mysql, and Data Table A contains four fields: id, name, password, and pid.

Id is the auto-increment primary key.

Pid is the id of the invitee at registration. the default value is 0.

Four data entries

Id name password pid
1 test 121121 0
2 Test 2 212121 1
3 Test 3 415454 1
4 Test 4 1212121 3

How can I use SQL statements to show who invited me? How many people have you invited?
------ Solution --------------------
Not tested. Adjust or ask again

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
;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.