0% found this document useful (0 votes)
86 views3 pages

SQL Queries for Retail Database Tasks

This document provides 24 SQL queries to perform tasks on a database for a retail company. The queries retrieve information from tables like REGION, STORE, CUSTOMER, PRODUCT, and TRANSACTION. They display data fields like region IDs, store details, customer names, product prices, total sales amounts, and more. The queries are also sorted and filtered in different ways, such as by region, name, price, total items sold, and other criteria.

Uploaded by

Kristen Butts
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)
86 views3 pages

SQL Queries for Retail Database Tasks

This document provides 24 SQL queries to perform tasks on a database for a retail company. The queries retrieve information from tables like REGION, STORE, CUSTOMER, PRODUCT, and TRANSACTION. They display data fields like region IDs, store details, customer names, product prices, total sales amounts, and more. The queries are also sorted and filtered in different ways, such as by region, name, price, total items sold, and other criteria.

Uploaded by

Kristen Butts
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
  • MODULE 5: SQL In Class Problems

TBANLT411 Data Management Instructor: Michael Turek

MODULE 5: SQL
In Class Problems, E5.1

E5.1 Write the SQL queries that accomplish the following tasks in the ZAGIMORE Retail Company
Sales Department Database:

E5.1 Write the SQL queries that accomplish the following tasks in the ZAGIMORE Retail Company
Sales Department Database:

E5.1.1 Display all the records in the table REGION.

E5.1.2 Display the StoreID and StoreZip for all stores.

E5.1.3 Display the CustomerName and CustomerZip for all customers, sorted alphabetically by
CustomerName.

E5.1.4 Display the RegionIDs of regions where we have stores (use only table STORE and do not
display the same information more than once).

E5.1.5 Display all the information for all stores whose RegionID value is C.

E5.1.6 Display CustomerID and CustomerName for all customers whose CustomerName begins with
a letter T.

E5.1.7 Display the ProductID, ProductName, and ProductPrice for products with a Product
Price of $100 or higher.

E5.1.8 Display the ProductID, ProductName, ProductPrice, and VendorName for all
products. Sort the results by ProductID.

E5.1.9 Display the ProductID, ProductName, ProductPrice, VendorName, and CategoryName for
all products. Sort the results by ProductID.

E5.1.10 Display the ProductID, ProductName, and ProductPrice for products in the category whose
CategoryName value is Camping. Sort the results by ProductID.

E.5.1.11 Display the ProductID, ProductName, and ProductPrice for products that were sold in the
zip code 60600. Sort the results by ProductID.

Database Systems, Edition 2.0 (Jukic et. al.) Chapter 05


TBANLT411 Data Management Instructor: Michael Turek

E.5.1.12 Display the ProductID, ProductName, and ProductPrice for Products whose VendorName
is Pacifica Gear that were sold in the region whose RegionName is Tristate. Do not display the same
information more than once (i.e., do not show the same product more than once). Sort the results by
ProductID.

E5.1.13 Display the TID, CustomerName, and TDate for sales transactions involving a
customer buying a product whose ProductName is Easy Boot.

E5.1.14 Display the RegionID, RegionName, and number of stores in the region for all regions.

E5.1.15 For each product category, display the CategoryID, CategoryName, and average price
of a product in the category.

E5.1.16 For each product category, display the CategoryID and the total number of items purchased
in the category.

E5.1.17 Display the RegionID, RegionName, and the total amount of sales (in dollars) in the
region for all regions. Display the total amount of sales as AmountSpent.

E5.1.18 Display the TID and the total number of items (of all products) sold within the transaction
for all sales transactions whose total number of items (of all products) sold
within the transaction is greater than five.

E5.1.19 For each vendor whose product sales exceed $700, display the VendorID, VendorName,
and total amount of sales in dollars. Display the total amount of sales as TotalSales.

E5.1.20 Display the ProductID, ProductName, and ProductPrice of the cheapest product.

E5.1.21 Display the ProductID, ProductName, and VendorName for products whose price is
below the average price of all products.

E5.1.22 Display the ProductID and ProductName of the product for the products whose total
quantity sold in all transactions is greater than 2. Sort the results by ProductID.

E5.1.23 Display the ProductID for the product that has been sold the most within all transactions
(i.e., that has the highest total quantity sold summarized across all transactions).

Database Systems, Edition 2.0 (Jukic et. al.) Chapter 05


TBANLT411 Data Management Instructor: Michael Turek

E5.1.24 Rewrite Query 30 using a join statement (no nested queries).

E5.1.25 Rewrite Query 31 using a join statement (no nested queries).

Database Systems, Edition 2.0 (Jukic et. al.) Chapter 05

Common questions

Powered by AI

The SQL query to list products in the 'Camping' category, sorted by ProductID, would be: SELECT ProductID, ProductName, ProductPrice FROM ProductTable WHERE CategoryName = 'Camping' ORDER BY ProductID. This command filters products by the Camping category and sorts the results by ProductID .

To find all products with a product price of $100 or higher, you would use the SQL query: SELECT ProductID, ProductName, ProductPrice FROM ProductTable WHERE ProductPrice >= 100. This query selects the ProductID, ProductName, and ProductPrice from the ProductTable where the ProductPrice is greater than or equal to $100 .

To calculate the average product price within each category, you would use: SELECT CategoryID, CategoryName, AVG(ProductPrice) AS AveragePrice FROM ProductTable GROUP BY CategoryID, CategoryName. This query averages the ProductPrice for each category by grouping the results based on CategoryID and CategoryName .

The SQL query to display the ProductID, ProductName, ProductPrice, and VendorName for all products, sorted by ProductID, would be: SELECT ProductID, ProductName, ProductPrice, VendorName FROM ProductTable ORDER BY ProductID. This retrieves the required fields and sorts them in ascending order based on the ProductID .

To display unique RegionIDs from regions with stores using only the STORE table, you would write: SELECT DISTINCT RegionID FROM STORE. This SQL query will ensure that only unique RegionIDs are displayed by using the DISTINCT keyword .

To avoid duplicate entries when listing products sold in the 'Tristate' region by 'Pacifica Gear', use: SELECT DISTINCT ProductID, ProductName, ProductPrice FROM SalesTable JOIN RegionTable ON SalesTable.RegionID = RegionTable.RegionID WHERE VendorName = 'Pacifica Gear' AND RegionName = 'Tristate'. The DISTINCT keyword ensures each product is listed only once .

To find the store count within each region, the SQL query is: SELECT RegionID, RegionName, COUNT(StoreID) AS StoreCount FROM StoreTable GROUP BY RegionID, RegionName. This query groups the results by RegionID and RegionName and uses the COUNT() function to determine the number of stores in each region .

The query to find products priced below the average price would be: SELECT ProductID, ProductName, VendorName FROM ProductTable WHERE ProductPrice < (SELECT AVG(ProductPrice) FROM ProductTable). This leverages a subquery to calculate the average price and then filters products priced below this average .

The SQL query to find the best-selling product by total transactions would be: SELECT ProductID FROM SalesTable GROUP BY ProductID ORDER BY SUM(QuantitySold) DESC LIMIT 1. This groups sales by ProductID, sums their quantities, and sorts them in descending order to select the one sold the most .

To display the cheapest product, the SQL query is: SELECT ProductID, ProductName, ProductPrice FROM ProductTable WHERE ProductPrice = (SELECT MIN(ProductPrice) FROM ProductTable). This uses the MIN() function to identify the lowest product price and then selects the corresponding product details .

TBANLT411 Data Management
Instructor: Michael Turek
MODULE 5: SQL
In Class Problems, E5.1
E5.1 Write the SQL queries that acc
TBANLT411 Data Management
Instructor: Michael Turek
 
E.5.1.12 Display the ProductID, ProductName, and ProductPrice for Produ
TBANLT411 Data Management
Instructor: Michael Turek
E5.1.24 Rewrite Query 30 using a join statement (no nested queries). 
 
E

You might also like