I am very new to using SQL or any coding for that matter so any advice would be appreciated!
I have wrote out an insert statement to insert data from mulitple times into a new table called detailed table. The query runs however it takes a while to complete (56 secs 106 msec)
I am wondering am i overcomplicating this query and if there is a simpler way to write this?
Detailed Table:
film_id | title | rating | store_id | times_rented
INSERT INTO TABLE detailed
SELECT f.film_id, f.tilte, f.rating, i.store_id, COUNT(r.rental_date) AS times_rented
FROM inventory i
JOIN flim f
ON i.film_id = f.film_id
JOIN rental r
ON r.inventroy_id = r.inventory_id
WHERE store_id = 1
GROUP BY f.film_id, store_id, rental_date;
second question/issue
INSERT INTO detailed
VALUES (123, 'New Movie', 'R', 1, '2004-01-02');
ERROR: invalid inout syntax for integer: “2004-01-02”
LINE 2: VALUES (123, ‘New Movie’, ‘R’, 1, ‘2004-01-02’);
I also tried to insert a new entry but get this error when it comes to the timestamp.
I tried different dates and added time e.i ‘2000-01-01 00:00:00’ but still recieve an error. The datatype is TIMESTAMP WITHOUT TIME ZONE
Sonia Acosta is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1