Group rows by Year Band Interval

后端 未结 3 454
[愿得一人]
[愿得一人] 2021-01-13 14:22

I have a table (tbl_people), in this table I have a datetime field I want to group and count the records in groups of 10 years... The result should be something like:

3条回答
  •  萌比男神i
    2021-01-13 14:27

    This will helps .

     select CONCAT(FLOOR(YEAR(from_unixtime(TIMESTAMP))/10)*10,'-',(FLOOR(YEAR(from_unixtime(TIMESTAMP))/10)*10)+9) as year , count(ID) from 
        TABLE group by FLOOR(YEAR(from_unixtime(TIMESTAMP))/10)*10;
    

提交回复
热议问题