Ask a SQL query statement

Source: Internet
Author: User
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

  • 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.