0

So I have the following Oracle SQL Database table:

create table Customer
(customerID char(25) not null, 
name char(50), 
address char(100), 
dateRegistered DATE, 
noOfDvdHiring int, 
primary key (customerID));

And I have the following query: List the unique numbers and names of all customers who are hiring more DVDs than the average number of DVDs currently hired by all customers.

I'm sure this should involve a nested query but I am unsure where to start?

I have tried:

SELECT customerID, name
FROM Customer
WHERE noOfDvdHire > AVG(noOfDvdHire);

But receive this error message: ORA-00934: group function is not allowed here

Thomas
  • 79
  • 8

2 Answers2

0

Try this

SELECT customerID, name
FROM Customer
WHERE noOfDvdHiring > (select AVG(noOfDvdHiring) from customer);
Vamsi Prabhala
  • 48,685
  • 4
  • 36
  • 58
0

2 ways... the difference is in execution plans

select * from (
  select customer_id, noOfDvdHire, avg(noOfDvdHire) over () avgg from Customer
) where noOfDvdHire > avgg

select customer_id, noOfDvdHire from Customer
  where noOfDvdHire >  (select AVG(noOfDvdHire) from customer);
are
  • 2,535
  • 2
  • 22
  • 27
  • Thank you, for both ways I get the following error: ORA-00904: "NOOFDVDHIRE": invalid identifier – Thomas Oct 28 '15 at 01:04