There is a customer table, one of the fields is stored in a phone number, the customer every time you buy a phone number, I now want to query this field repeatedly record the most, and arranged in sequence, the SQL should be how to write it.
Customer table name PartyList
The field that stores the customer phone number is phonum varchar (15)
The structure of the table is probably like this
Zhang San Beijing 0108956878
John Doe Shanghai 021545787
Little Shanghai 13800138000
Little four Shanghai 13800138000
Xiao Wu Guangzhou 0205855843
For example, the result of the query is
13800138000 29 plays Xiao Wang
020184587 18 plays Xiao Li
This, thank you.
Reply to discussion (solution)
Use this to try:
SELECT *,count (Phonum) as Nums from PartyList GROUP by Phonum ORDER by Nums DESC
Use this to try:
SELECT *,count (Phonum) as Nums from PartyList GROUP by Phonum ORDER by Nums DESC
Well, yes, thank you, can you help me to explain this SQL, I found out after the result is added a field nums
Select *,count (phonum)//This I know, query the total number of a table, but the comma ', ' I don't know what it means
As I also know, alias, and then query partylist this table name
Select Username,userpass from ..... Here ', ' and he learns the same as the comma.
In
Use this to try:
SELECT *,count (Phonum) as Nums from PartyList GROUP by Phonum ORDER by Nums DESC
Well, yes, thank you, can you help me to explain this SQL, I found out after the result is added a field nums
Select *,count (phonum)//This I know, query the total number of a table, but the comma ', ' I don't know what it means
As I also know, alias, and then query partylist this table name
In the world of SQL, we can also consider the field as a variable, which can be evaluated by an as assignment, and then the data can be obtained.
Thank you so much