How do I use an aggregate function, e.g. count or max of dvds where I have 4 tables & the table I want to get a count or max from (rental) has a composite key that is a combo of dvd and copy
How do I use an aggregate function, e.g. count or max of dvds where I have 4 tables & the table I want to get a count or max from (rental) has a composite key that is a combo of dvd and copy. I want to know the number of dvds sold out/not sold out (compare the number of dvds out but not returned/returned in rental table to the numbercopies in dvd)
Tables
dvd: dvd_id, title, numbercopies
copy: copy_id
dvdcopy: dvdcopy_id, dvd_id, copy_id
rental: rental_id, dvdcopy_id, rentaldate , rentalreturn
I've tried using Oracle's SQL Developer to do the following:
(for dvds sold out)
My code gives me a ORA-00937'Not a single-group group function' error message. I would appreciate any help!
How do I use an aggregate function, e.g. count or max of dvds where I have 4 tables & the table I want to get a count or max from (rental) has a composite key that is a combo of dvd and copy. I want to know the number of dvds sold out/not sold out (compare the number of dvds out but not returned/returned in rental table to the numbercopies in dvd)
Tables
dvd: dvd_id, title, numbercopies
copy: copy_id
dvdcopy: dvdcopy_id, dvd_id, copy_id
rental: rental_id, dvdcopy_id, rentaldate , rentalreturn
I've tried using Oracle's SQL Developer to do the following:
(for dvds sold out)
Code:
SELECT dc.dvd_id,
dc.title,
dc.copyid,
COUNT(d.dvd_id)
AS numberdvd,
FROM dvdcopy dc
JOIN dvd d
ON dc.dvd_id=m.dvd_id
JOIN rental r
ON r.dvdcopy_id=d.dvd_id
WHERE rentaldate Is Not Null
AND rentalreturn Is Null;
GROUP BY dc.dvd_id,
dc.copy_id;
Comment