I am currently working a school project based on database application. Im using MS Access 2016 to do this.
So the database system is about cinema ticketing system.
Currently I'm stuck at this situation:
I have a movie list.
Table : MOVIES
Attr: MovieID, MovieName, Genre, Rating, MoviePic
This movie list have their respective showtime
Table: SHOWTIMES
Attr: Time, MovieID, HallID
One movie can have many showtimes
So, once I click a movie, I will have a window showing their respective showtime.
When the showtime window open, I will have a button that say "Select this showtime"
So, to booked a showtime, I create a new table called "Booked Showtime"
Table : BOOKED SHOWTIMES
Attr: MovieID, Time, HallID
So, how to append user selected showtime to the "Booked Showtime" table?
Actually the "Showtime" window that open when I clicked at a movie is a query as it will show showtime for the clicked movie..thats why the title of the question is "..append query result.."..I need to know how to append to the "Booked Showtime" table based onthe query result of the showtime..
currently I have this query:
INSERT INTO [BOOKED SHOWTIMES] ( [Time], MovieID, HallID )
SELECT SHOWTIMES.Time, SHOWTIMES.MovieID, SHOWTIMES.HallID
FROM CUSTOMERS, SHOWTIMES INNER JOIN [BOOKED SHOWTIMES] ON SHOWTIMES.Time = [BOOKED SHOWTIMES].Time
WHERE (((SHOWTIMES.Time)=[Forms]![SHOW SHOWTIME]![Time]) AND ((SHOWTIMES.MovieID)=[Forms]![SHOW SHOWTIME]![MovieID]) AND ((SHOWTIMES.HallID)=[Forms]![SHOW SHOWTIME]![HallID]));
so the query above didnt work as nothing ( You are about to append 0 rows ) is added to the "Booked Showtimes" table...
Sounds like you can use a normal insert query, and not INSERT INTO ... SELECT:
INSERT INTO [BOOKED SHOWTIMES] ( [Time], MovieID, HallID )
VALUES([Forms]![SHOW SHOWTIME]![Time], [Forms]![SHOW SHOWTIME]![MovieID], [Forms]![SHOW SHOWTIME]![HallID])
However, I can't see the relevance of the customers table, and it looks like you're doing nothing with that table.
Related
I have a simple query that I need to execute which will return all users who have watched the same movies, the date they did so and the number of times each movie was watched. The result should be grouped by movie title.
Say I have movie title: Gladiator and Prometheus. The result should be like:
Gladiator: Watched: 10 times| by: Alan, Bruce, Cecil, Marlon, etc| on: 10/01/2020, 1/11/2019, etc
Prometeus: Watched: 7 times| by: Julia, Baner, Alan, Marlon, etc | on: 10/01/2020, 1/11/2019, etc
I have MOVIE table, USER table, VIEW table
Some infos that might help you understand my problem:
MOVIE has view count row
VIEW has date row
USER has name, etc
My question is a bit similar to this: Query on all the people who has watched the same movies as I did but I wasn't able to adapt the solution to my case.
How can I achieve this?
I am assuming the following table structures:
movie: movie_name, view_count
user: user_name, age, city
view: movie_name, user_name, view_date
The query can be:
select m.movie_name as movie,
m.view_count as watched,
listagg(v.user_name, ',') as by,
listagg(v.view_date) as on
from movie m, view v
where m.movie_name = v.movie_name
group by m.movie_name, m.view_count;
Group by function listagg is available in Oracle's SQL. Microsoft's SQL has similar string_agg, in MySql group_concat etc.
I've created some tables in MySQL and I'm trying to select the data that's in those tables so that they get displayed. I have the following tables. Formed, Track, Album, Band, Customers and I have got the primary and foreign keys within the tables. I've also used the Insert into statement to insert data into the tables so there is data within the tables. I'm trying to get all the albums from a certain band to be displayed and I'm following the example below
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
Which can be found at W3Schools, to produce the following statement:
SELECT Album.AlbumID, Album.Title, Band.BandName
FROM Album
INNER JOIN Band
ON Album.BandID = Band.BandID
ORDER BY Band.BandName;
And this statement that I've made does create the table headers but doesn't display any data as shown here.
EDIT
In all the tables I've created, I hav got the primary key as an int AUTO_INCREMENT
EDIT #2
I've now changed it so that I have:
SELECT Album.AlbumID, Album.Title, Band.BandName
FROM Band
LEFT JOIN Album
ON Album.BandID = Band.BandID
ORDER BY Band.BandName;
Which displays only the band name and gets a NULL values for the AlbumID and Title
EDIT #3 Completed
I've managed to edit it so now I have the script working. It's as follows:
SELECT Album.AlbumID, Album.Title, Band.BandName
FROM Album
LEFT JOIN Band
ON Album.BandName = Band.BandName
ORDER BY Band.BandName;
I really can't wrap my head around this update sql statement.
I have the following schema for a copy table and a rental table :
copy (
copy_id ,
movie_id ,
branch_id ,
primary key (copy_id));
rental (
customer_id,
copy_id ,
outdate ,
returndate ,
primary key (customer_id,copy_id,outdate));
There will be multiple copies of the same movie. for a single movie_id, we can have multiple copy_id.
Each copy of a movie has a globally unique copy_id. So copies of 2 different movies cannot have the same copy_id.
There are multiple branches that have a copy of the movie, and certainly the copy_id will be unique.
The same movie and copy will definitely appear in rented multiple times, if it has been rented more than once.
I need to write a update statement such that - say we have 10 copies of a movie at a branch, and a time span of 30 days, so out of 300 rental days(30 days * 10 copies) the copies need to be rented out for at least 290 rental days. If this is true then I need to add another copy of that particular movie at that branch.
I tried to explain the problem in the best possible way I could. In short, I need to add a copy if the movie is rented out 90% of the time at a branch.
select branch_id, movie_id, count(*) from copy group by branch_id, movie_id
this query is branchs movie count. maybe you already have branch table, use that.
SELECT DATE_FORMAT(outdate, '%Y%m'),branch_id, movie_id, SUM(DATEDIFF(returndate , outdate)) FROM copy AS c INNER JOIN rental AS r ON c.copy_id = r.copy_id
GROUP BY DATE_FORMAT(outdate, '%Y%m'),c.branch_id, c.movie_id
this query is monthly rental time per branch and movie.
that query is basic query for calculate. and you can make logic like
if monthly rental time + new rental time > branchs rental limit
(
add new copy request
)
I have a table that holds the movie information. It has ID, title and so on. I have another table called categories where I have the available categories; action, drama and so on.
Each movie can be in many categories. So I created a view and joined these tables. Now the view displays a row for each category even if the movie is repeated.
I need to have have a single row for each movie and have categories as something like : 'Action, Drama, Comedy' (which is basically all categories from tbl_movies_categories).
How should I join tables/create view to achieve this?
This is the proper way:
Group By a unique ID, then use group_concat() to concat the values together.
CREATE VIEW `vw_metadata` AS
select
`vw_movies`.`id` AS `id`,
...
group_concat(`vw_movies_categories`.`title_category`
separator ',') AS `categories`,
from
(`vw_movies`
left join `vw_movies_categories` ON (`vw_movies_categories`.`movie_id` = `vw_movies`.`id`))
group by `vw_movies`.`id`
I'm a beginner to access and I made a database where I currently have two tables:
Product list table that has 3 columns: ProductID, Description, Description2
A scan table where the user will use a barcode scanner and scan the barcode into the table. It only has 2 columns: ID, and Barcode
I have a query where the first column is the raw barcode and the second is a mid function expression(?) where I extract the information such as product code ( I will add different columns, later, extracting weight, pack date, serial) from the barcode.
Currently, I would like for the the third column to show the Description and Description fields from the product list table. In excel I can do a vlookup, and I have been reading up on Dlookup, but I was wondering if there is an easier alternative to Dlookup because I can't get it to work. Thanks in advance!
Let us say that the query to extract product code is:
SELECT Barcode, Mid(Barcode,6,3) As ProductID FROM Barcodes
It is possible that you have an number data type for ProductID in the Products table, in which case you will have to ensure you have a number data type in the query, you can do this like so:
SELECT Barcode, CLng(Mid(Barcode,6,3)) As ProductID FROM Barcodes
You can either add this saved query to the Query Design Window along with you Product table and drag the ProductID field from one table to the other to create a join:
Or you can build a query using SQL view of the Query Design Window:
SELECT q.Barcode, Products.ProductID, Products.Description
FROM (
SELECT Barcode, Mid(Barcode,6,3) As ProductID
FROM Barcodes) As q
INNER JOIN Products
ON q.ProductID = Products.ProductID
Of course with the second option, you will have to get everything right for your set up.