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

  • Home
  • SEARCH
  • 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 8794411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:14:51+00:00 2026-06-13T23:14:51+00:00

I have two tables in my database that Im trying to use one Query

  • 0

I have two tables in my database that I”m trying to use one Query to get data from both for a specific report.

Table one is “Movies” and it has these fields:

  • Movies_ID
  • Name
  • Season

Table two is “Boxoffice” sales income for each movie:

  • Boxoffice_ID
  • Movies_ID
  • Date
  • Amount

I want to run a query to compare the opening weekends for each movie in a given season and return them as one dataset with the amounts collected added together. So I want to take each movie and get the first three days of box office for each film and add them up so that I get back a query like this

  1. Movie A, 49.1 Million
  2. Movie B, 42.2 Million
  3. Movie C, 29.5 Million

Please note the amount collected only needs to output the number and I’ll take care of the formatting. I’m just having trouble figuring out how to only query the first three days of box office for each movie and adding them together.

I know I could run one query and get the movies with box office and then loop over that and re-query the database but I know that with a lot of movies that isn’t the most efficient way of doing things. I’m not sure if there is a way to do all of this (first three days of each movie added together) in one query but I wanted to see if someone with more advanced knowledge could help me out.

  • 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-13T23:14:52+00:00Added an answer on June 13, 2026 at 11:14 pm
    SELECT  a.Name, SUM(COALESCE(b.Amount,0)) totalAmount
    FROM    Movies a
            LEFT JOIN BoxOffice b
                ON a.Movies_ID = b.Movies_ID
    WHERE   b.date BETWEEN DATE_ADD(CURDATE(),INTERVAL -3 DAY) AND CURDATE()
    GROUP BY a.Name
    

    if the value of CURDATE() is 2012-11-06 (which is today), it will calculate from 2012-11-03 until 2012-11-06.

    followup question, how do you calculate the date? by day? by week? or what?

    UPDATE 1

    SELECT  a.Name, SUM(COALESCE(b.Amount,0)) totalAmount
    FROM    Movies a
            LEFT JOIN BoxOffice b
                ON a.Movies_ID = b.Movies_ID
            LEFT JOIN
            (
                SELECT  movies_ID, MIN(date) minDate
                FROM    BoxOffice
                GROUP BY Movies_ID
            ) c ON a.Movies_ID = c.Movies_ID
    WHERE   DATE(b.date) BETWEEN DATE(c.minDate) AND 
                                 DATE(DATE_ADD(c.minDate,INTERVAL 3 DAY))
    GROUP BY a.Name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to import data from a large database. I have two tables
I'm simply trying to get data from two sql server db tables using ado.net
I have two tables in my database that look like that: Customer: C_ID city
I have two tables in my database schema that represent an entity having a
I have a database that which contains two tables, links and tour. Tour is
I have two separate sets of tables in the same database that model the
I have a database two tables and a linking table that I need a
I have a very simple database table that joins two other tables in a
Basically I have a database with two tables, that is, Updates table and Images
I have a legacy data base and a relation one-to-one between two tables. The

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.