SQL query statement

Source: Internet
Author: User
An SQL query statement has a customer Table. one of the fields stores the phone number. each time the customer buys the phone number, now I want to query the most repeated records of this field and arrange them in sequence. how should I write this SQL statement.

Customer table name partylist
The field used to store the customer's phone number is phonum varchar (15)

The table structure is like this.

Zhang San, Beijing 0108956878
Li Si, Shanghai 021545787
Little Shanghai 13800138000
4th Shanghai 13800138000
Wu Guangzhou 0205855843

For example, the query result is

13800138000 (29 times) Wang
020184587 18 times Xiao Li

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 explain this SQL statement? after I query it, I see that the result is added with a field NUMS

Select *, count (phonum) // I know that the total number of a table is queried, but the comma ',' I don't know what it means
As I also know, alias, followed by querying the name of the table partylist

Select username, userpass from... ',' has the same effect 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 explain this SQL statement? after I query it, I see that the result is added with a field NUMS

Select *, count (phonum) // I know that the total number of a table is queried, but the comma ',' I don't know what it means
As I also know, alias, followed by querying the name of the table partylist
In the SQL world, fields can also be considered as variables, which can be computed. data can be obtained through the as value assignment.

Thank you very 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.