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

Worksheet 2. DML-Aggregate Functions

This document is a worksheet for a database manipulation exercise focused on aggregate functions using a pet shop inventory. It includes instructions for creating a database, a table, inserting records, and writing SQL queries to answer specific questions about the inventory. The tasks involve calculating totals, prices, and discounts based on the provided data schema.

Uploaded by

seanrs.salcedo
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)
4 views

Worksheet 2. DML-Aggregate Functions

This document is a worksheet for a database manipulation exercise focused on aggregate functions using a pet shop inventory. It includes instructions for creating a database, a table, inserting records, and writing SQL queries to answer specific questions about the inventory. The tasks involve calculating totals, prices, and discounts based on the provided data schema.

Uploaded by

seanrs.salcedo
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
You are on page 1/ 4

Chapter 2 | Data Manipulation Language 1

Worksheet 2: Using the Aggregate Functions

The table below stores the inventory of a pet shop. Study the purpose of each column
then answer the questions that follow. Answer completely by writing both the query and
the result, unless the instruction says otherwise. Enjoy!

● Create a Databse named YourLastnameFirstnameSection_Aggregate.

● In your database, create a table named stocks using the following schema.

● Insert the following records in the created table and write atleast one INSERT
Query below.

INSERT INTO
_________________________________________________________________
____________________________________________________________________________
____________________________________________________________________________
____________________________________________________________________________

STOCKS
ID CATEGORY BREED GENDER IN_STOCK PRICE
1 Rabbit Holland Lop M 10 600
2 Rabbit Holland Lop F 17 800
3 Dog Chow-chow M 2 15000
4 Dog Chow-chow F 2 25000
5 Rabbit Angora M 10 1500
6 Rabbit Angora F 7 1800
7 Guinea Peruvian M 5 550
8 Guinea Peruvian F 10 1500

1 Advanced Database Systems | MarSU-CICS


Chapter 2 | Data Manipulation Language 2

Answer the following questions by applying the aggregate functions discussed in the
modile. Write your query statement on the spaces provided and the corresponding
output that will answer the questions below. You may screenshot the result and paste in
the spaces provide.
1. How many animals does this pet shop have?
Query Syntax:
SELECT

FROM

Result:

2. How much will a customer pay if he wants to buy a pair of Chow-chows?


Query Syntax:
SELECT

FROM

WHERE

Result:

2 Advanced Database Systems | MarSU-CICS


Chapter 2 | Data Manipulation Language 3

3. How many rabbits are available? Show the result by breed.


Query Syntax:
SELECT

FROM

WHERE

GROUP BY

Result:

4. How many breeds of each animal does this pet shop have?
Query Syntax:
SELECT

FROM

GROUP BY

Result:

3 Advanced Database Systems | MarSU-CICS


Chapter 2 | Data Manipulation Language 4

5. Let us suppose that this pet shop is giving 25% discount for purchasing pair of any
animal. Write a query that will show the matrix below:
CATEGORY BREED PricePerPair Discount
Dog Chow-chow 40000 10000
Guinea Pig Peruvian 2050 512.50
Rabbit Angora 3300 825
Rabbit Holland Lop 1400 350

SELECT

FROM

GROUP BY

● Export the database and include it the submission. Save this file in PDF
using the format “Worksheet2-2-YourLastnameFirstname-Section.pdf”

4 Advanced Database Systems | MarSU-CICS

You might also like