0% found this document useful (0 votes)
3 views4 pages

330 SQL Sample Queries

The document contains a series of SQL statements for querying customer, supplier, product, and employee data from a database. It includes examples for listing customers in specific locations, suppliers in certain cities, products above a price threshold, and aggregating customer counts by employee and supplier. The queries demonstrate various SQL functionalities like filtering, joining tables, and grouping results.

Uploaded by

nknguyen
Copyright
© All Rights Reserved
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)
3 views4 pages

330 SQL Sample Queries

The document contains a series of SQL statements for querying customer, supplier, product, and employee data from a database. It includes examples for listing customers in specific locations, suppliers in certain cities, products above a price threshold, and aggregating customer counts by employee and supplier. The queries demonstrate various SQL functionalities like filtering, joining tables, and grouping results.

Uploaded by

nknguyen
Copyright
© All Rights Reserved
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

Sample SQL statements

--List the names of customers in the US.

SELECT * FROM Customers


WHERE Country='Germany'
and city = 'Berlin'

-- List the supplier names in New Orleans.

Select SupplierName
from Suppliers
where city = 'New Orleans'

--List the products whose prices are higher than 60.

SELECT *
FROM Products
where price > 60

--List the Supplier IDs, Supplier names, and Product Prices of the products whose prices
are higher than 60.

SELECT [Link], SupplierName, ProductName, Price


FROM Suppliers S, Products P
where [Link] = [Link]
and Price > 60
--List the employees' names, customer names, city, and the country of the employees who
take care of customers in Portland, USA.

SELECT [Link], [Link], [Link], [Link], [Link], [Link]


FROM Employees E, orders O, Customers C
where [Link] = [Link]
and [Link] = [Link]
and [Link] = 'Portland'
and [Link] = 'USA'

--List the employee names and the number of customers in the US they serve.

SELECT [Link], [Link], [Link], count( [Link]) Num_Customers


FROM Employees E, orders O, Customers C
where [Link] = [Link]
and [Link] = [Link]
and [Link] = 'USA'
Group by [Link], [Link], [Link]
--List the names of the suppliers who supply products to the customers in the US.

Select [Link], [Link], [Link]


from Suppliers S, products P, OrderDetails OD, orders O, customers C
where [Link] = [Link]
and [Link] = [Link]
and [Link] = [Link]
and [Link] = [Link]
and [Link] = 'USA'

--List the suppliers and the number of customers they supply in the US, specifically those
with more than five customers.

Select [Link], count([Link]) C_Cname


from Suppliers S, products P, OrderDetails OD, orders O, customers C
where [Link] = [Link]
and [Link] = [Link]
and [Link] = [Link]
and [Link] = [Link]
and [Link] = 'USA'
group by [Link]
having count([Link]) > 5

You might also like