简体   繁体   中英

Group MySQL values from table

I'm sure this is possible I don't know where to start. I have a table with 2000 values they are on the range from 0 to 100. I want to query the table to get the different groups of values. ie I have those values 5, 10 , 5 , 2 , 2, 0, 1, 1, 1, 1, 1, 10, 2

I want an output like this:

 Value - Number_of_times 
   0            1
   1            5
   2            3
   5            2
  10            2

You need to group your results by your field, and take the COUNT() of each group:

SELECT   myfield, COUNT(*) as number_of_times
FROM     mytable
GROUP BY myfield

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM