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
- Movie A, 49.1 Million
- Movie B, 42.2 Million
- 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.
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