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.