Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8955293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:31:10+00:00 2026-06-15T14:31:10+00:00

I have a table (tbl_people), in this table I have a datetime field I

  • 0

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:
| count    | year           |
| 1000     | 1980-1989 |
| 250       | 1990-1999 |

I can write multiple queries to do it, but that means I’ll have to write different queries for each range. Is there a way to dynamically increment from the least year upwards (10 year intervals) and count the number of records within the intervals?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:31:11+00:00Added an answer on June 15, 2026 at 2:31 pm

    First calculate the decade for each row

    select floor(year(`year`) / 10) * 10 as decade
    from tbl_people
    

    and then use this intermediate result for counting SQL Fiddle

    select count(*), decade, decade + 9
    from (select floor(year(`year`) / 10) * 10 as decade
          from tbl_people) t
    group by decade
    

    or this SQL Fiddle, if you want the decade in one column

    select count(*) as count, concat(decade, '-', decade + 9) as year
    from (select floor(year(`year`) / 10) * 10 as decade
          from tbl_people) t
    group by decade
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table (tbl_world) which look like this id | first_name | last_name
I have a table called tbl_loans which has the field loan_number . Loan numbers
I have a table structure like this (vertical design). I can have unlimited number
I have a postgres table like this: CREATE SEQUENCE seq; CREATE TABLE tbl (id
I have a table tbl_orders . It has a quantity field quantity . In
i have a table 'tbl_department' with 2 fields 'dpt_id' n 'dpt_name' i want to
I have table with the following structure: FirstName|MiddleName|PatientID I want in other table to
I have a table called tbl_users A broken down version of it for this
if i have a table like this tbl_attributes --------------- id_attrib (auto incremented, primary key)
I have a table whose schema is declare @tbl table(field varchar(20)) insert into @tbl

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.