Info ~ travel musings for the masses

My database professor decided to try and throw a weird/hard problem at me but after some playing with Oracle I was able to figure it out.

Basically, I have a table of customers, each customer has a name and an annual revenue. What my professor wanted was to select the customers who’s annual revenue was higher than the average of all of the annual revenues of all customers less themselves. Sounds somewhat difficult. Not really.

SELECT cust_name, cust_annual_rev

FROM customer c

WHERE cust_annual_rev >

   (SELECT AVG(cust_annual_rev)

    FROM customer

    WHERE cust_id <> c.cust_id);

Wasn’t too difficult… Maybe I’ll get some extra credit or something.


No comments yet.

Leave a Reply

Basic HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS

This site uses Akismet to reduce spam. Learn how your comment data is processed.