AznDevil92
AznDevil92

Reputation: 554

SQL Statement for Division - Oracle 11g

I am trying to write a SQL query where I have to select title, year and take the movie cost and divide by the price rent fee for each movie that has a price.

PRICE to MOVIE entity is a 1:M, therefore PRICE_CODE is the FK in entity MOVIE.

This is what I have gotten so far but it keep stating that my operator is invalid.

Can anyone help?

SELECT movie_title, movie_year, movie_cost
FROM MOVIE
JOIN PRICE
ON movie.price_code = price.price_code
WHERE (movie_cost)/(price_rentfee);

Upvotes: 0

Views: 395

Answers (2)

PM 77-1
PM 77-1

Reputation: 13334

Your were close:

SELECT movie_title, movie_year, movie_cost/price_rentfee As "Cost to price ratio"
FROM MOVIE
JOIN PRICE
ON movie.price_code = price.price_code
WHERE COALESCE(price_rentfee, 0) > 0;

If by any chance you made a typo and movie_cost should've been movie.cost and price_rentfee - price.rentfee then it would be like follows:

SELECT movie_title, movie_year, movie.cost/price.rentfee As "Cost to price ratio"
FROM MOVIE
JOIN PRICE
ON movie.price_code = price.price_code
WHERE COALESCE(price.rentfee, 0) > 0;

Upvotes: 1

Konrad
Konrad

Reputation: 36

Try this:

SELECT movie_title, movie_year, (movie_cost)/(price_rentfee) as 'cost'
FROM MOVIE
JOIN PRICE
ON movie.price_code = price.price_code;

Upvotes: 0

Related Questions