0% found this document useful (0 votes)
51 views2 pages

Show Products That Are More Expensive Than Average: Create

This document shows how to write an SQL query to select products from a table where the product price is greater than the average price of all products. The query selects the product name, price, quantity on hand, and last stock date from the product table where the product price is higher than the average price calculated from the same table. It then displays the results, which are two products whose price exceeds the overall average.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views2 pages

Show Products That Are More Expensive Than Average: Create

This document shows how to write an SQL query to select products from a table where the product price is greater than the average price of all products. The query selects the product name, price, quantity on hand, and last stock date from the product table where the product price is higher than the average price calculated from the same table. It then displays the results, which are two products whose price exceeds the overall average.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Show products that are more expensive than average

SQL> CREATE TABLE product ( 2 product_name VARCHAR2(25) PRIMARY KEY, 3 product_price NUMBER(4,2), 4 quantity_on_hand NUMBER(5,0), 5 last_stock_date DATE 6 ); Table created. SQL> SQL> INSERT INTO product VALUES ('Product 1', 99, '15-JAN-03'); 1 row created. SQL> INSERT INTO product VALUES ('Product 2', 75, '15-JAN-02'); 1 row created. SQL> INSERT INTO product VALUES ('Product 3', 50, '15-JAN-03'); 1 row created. SQL> INSERT INTO product VALUES ('Product 4', 25, null); 1 row created. SQL> INSERT INTO product VALUES ('Product 5', 9.95,1234, '15-JAN-04'); 10000, 100, 1000,

1,

1 row created. SQL> INSERT INTO product VALUES ('Product 6', 45, 1, TO_DATE('December 31, 2008, 11:30 P.M.','Month dd, YYYY, HH:MI P.M.')); 1 row created. SQL> SQL> SELECT * FROM product 2 WHERE product_price > (SELECT AVG(product_price) FR OM product); PRODUCT_NAME PRODUCT_PRICE QUANTITY_ON_HAND LAST_STOC ------------------------- ------------- -----------------------Product 1 99 1 15-JAN-03 Product 2 75 1000 15-JAN-02

You might also like