outputting too many

Reply

Join Date: Apr 2008
Posts: 108
Reputation: christiangirl is an unknown quantity at this point 
Solved Threads: 1
christiangirl christiangirl is offline Offline
Junior Poster

outputting too many

 
0
  #1
Oct 18th, 2009
I am just starting to learn sql and have to questions from my homework assignment.
The first is this:
Write a query which will project the average rental price and number of such videos for videos of Classic movies --- BUT! You must write this without explicitly using the category code for Classic movies; you must use the name 'Classic' in your query instead. Rename the columns to be "Avg Cost - Classic" and "# Videos - Classic", respectively, using precisely these spaces and case.

The code I wrote is:
  1. SELECT AVG(vid_rental_price) "Avg Cost - Classic", COUNT(*) "#
  2. Videos Classic"
  3. FROM movie_category, video
  4. WHERE movie_category.category_code =
  5. (
  6. SELECT category_code
  7. FROM movie_category
  8. WHERE category_name = 'Classic'
  9. )
  10. AND vid_rental_price <
  11. (
  12. SELECT AVG(vid_rental_price)
  13. FROM video
  14. );

But count is outputting a larger number then it is supposed to. I think it is counting all of the rentals, not just the ones labeled classic. But I am not sure how to fix this.

The second question is:
Using a join, (and NOT using ANY nesting or sub-selects), project the last names, first names, and date the video was due for clients who have ever rented the video with ID '130012'.

and my code is:
  1. prompt 2-5
  2. SELECT DISTINCT client_lname, client_fname, date_due, vid_id
  3. FROM client, rental
  4. WHERE rental.vid_id = '130012';
It is outputting more rows then it should, and outputs that all vid_id's are 130012. I think this has to do with the join, but am not sure how to do this without a join.

Thanks!
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,080
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 124
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic
 
0
  #2
33 Days Ago
kindly post your table structure.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC