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 7398679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:54:01+00:00 2026-05-29T03:54:01+00:00

I have a table with columns year and movie ids, and for each year,

  • 0

I have a table with columns year and movie ids, and for each year, I want to get the count for of the ids with year within 10 years of that year.

e.g. if I had the data:
year | id
1950 1
1951 2
1960 1

I would want to return
year | count
1950 3
1951 3
1960 1

I thought I could do it like this

select m1.year, count(m1.id)
  from movie m1
  join movie m2
    on m1.id=m2.id
 where m2.year>=m1.year
   and m2.year<=m1.year+9
 group by m1.year
 order by m1.year;

but this just returns the movies in each year (or seems to, since the results are identical to select year, count(id) from movie group by year;)

what am I doing wrong?

  • 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-05-29T03:54:02+00:00Added an answer on May 29, 2026 at 3:54 am

    Joining on ids is not what you want: you’ll get a 1<=>1 relationship most probably (May I assume id is a key?

    SELECT m1.year, COUNT(*)
      FROM (SELECT DISTINCT year FROM movie) m1
     CROSS JOIN movie M2
     WHERE m2.year - m1.year BETWEEN 0 AND 9
     GROUP BY m1.year
     ORDER BY m1.year
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Table with columns: Month and Year, and other data. All row in
I have a table with 2 columns. car year. I want to do a
I have a table that has columns YEAR and MONTH, which are varchars, which
I have a cars sqlite database with one table that has 3 columns: year,
I have table with columns Year | Day | CreatedDate. I want to update
I have a table that has two columns both of them are continuous data.
I have a table in SQL Server 2005 database that has following columns: Id,ProductName,Year,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
i have day, month, year, value columns in one table, here i need to
The table columns have the data type BLOB and CLOB. What are the corresponding
I have table with 3 columns A B C. I want to select *

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.