0% found this document useful (0 votes)
9 views

sql

The document contains a series of SQL queries for retrieving product information from a database. Queries include selecting product names and prices, filtering products by price range, calculating averages, counting products, and joining with manufacturer data. It also includes a query to find the cheapest product in the store.

Uploaded by

rakhmatovaa
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

sql

The document contains a series of SQL queries for retrieving product information from a database. Queries include selecting product names and prices, filtering products by price range, calculating averages, counting products, and joining with manufacturer data. It also includes a query to find the cheapest product in the store.

Uploaded by

rakhmatovaa
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

-- 1.

Select the names of all the products in the store


SELECT Name FROM Products;

-- 2. Select the names and the prices of all the products in the store.
SELECT Name, Price FROM Products;

-- 3. Select the name of the products with a price less than or equal to $200.
SELECT Name FROM Products WHERE Price <= 200;

-- 4. Select all the products with a price between $60 and $120.
SELECT * FROM Products WHERE Price BETWEEN 60 AND 120;

-- 5. Select the name and price in cents (i.e., the price must be multiplied by
100).
SELECT Name, Price * 100 AS PriceInCents FROM Products;

-- 6. Compute the average price of all the products.


SELECT AVG(Price) AS AveragePrice FROM Products;

-- 7. Compute the average price of all products with manufacturer code equal to 2.
SELECT AVG(Price) AS AveragePrice FROM Products WHERE Manufacturer = 2;

-- 8. Compute the number of products with a price larger than or equal to $180.
SELECT COUNT(*) AS NumberOfProducts FROM Products WHERE Price >= 180;

-- 9. Select the product name, price, and manufacturer name of all the products.
SELECT Products.Name, Products.Price, Manufacturers.Name AS ManufacturerName
FROM Products
JOIN Manufacturers ON Products.Manufacturer = Manufacturers.Code;

-- 10. Select the name and price of the cheapest product.


SELECT Name, Price FROM Products ORDER BY Price ASC LIMIT 1;

You might also like