Forum Moderators: coopster

Message Too Old, No Replies

MySql Query help

Number frequency

         

jgalba

9:12 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



How do I determine how many times a number is listed in a single table. For instance a table with many different numbers in it and I want to know how many times the number 32 is listed. To take it further, how many times each number is listed in the table and have the output prioritize from most frequently listed to least.

Thanks in advance.

mcibor

9:33 pm on Jan 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Function count(number) returns the number of all found records.
To find how many 32s there are simply ask

SELECT count(*) FROM table WHERE number='32';

I don't know yet how to find appearances of all numbers, sorry.

mcibor

9:36 pm on Jan 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To select more ask:

SELECT number, COUNT(*) FROM table GROUP BY number;

this question I found in mySQL manual a4 on 210 page.

Hope you can use this code.
Best wishes!

freeflight2

9:42 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



prioritize from most frequently listed to least.

SELECT number, COUNT(*) as c FROM table GROUP BY number ORDER by c DESC;

jgalba

2:29 am on Jan 4, 2005 (gmt 0)

10+ Year Member



Thanks everyone. I'll give these a try.

jgalba

8:55 pm on Jan 4, 2005 (gmt 0)

10+ Year Member



Hi all. I can't seem to get this to produce the results I want. They should look like this listed in priority of total times listed in a field in a table.

10 20 total occurances
11 13 total occurances
12 9 total occurances

Any ideas?

freeflight2

8:58 pm on Jan 4, 2005 (gmt 0)

10+ Year Member



then you would have to ORDER according to a particular field:

SELECT number, COUNT(*) as c, field FROM table GROUP BY number ORDER by field DESC;

or similar, etc... try playing around with the SELECT, that's the best way to learn SQL.