0% found this document useful (0 votes)
258 views23 pages

D427 Practice Test 1 With ANSWER KEY 3

The document is a practice test consisting of 32 questions related to database concepts, SQL commands, and table structures. It includes multiple-choice questions, SQL statement writing tasks, and scenarios involving foreign keys and data types. The test aims to prepare individuals for an assessment by emphasizing the importance of scoring at least 17 out of 25 to pass.

Uploaded by

Tee Shanice
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
258 views23 pages

D427 Practice Test 1 With ANSWER KEY 3

The document is a practice test consisting of 32 questions related to database concepts, SQL commands, and table structures. It includes multiple-choice questions, SQL statement writing tasks, and scenarios involving foreign keys and data types. The test aims to prepare individuals for an assessment by emphasizing the importance of scoring at least 17 out of 25 to pass.

Uploaded by

Tee Shanice
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

D427 Practice Test 1

1. Seattle, WA 98111
USA
How many attributes are present in the address fragment?

a. 1
b. 2
c. 3
d. 4

2. The Book table has the following columns:


genre – varchar(20)
pages – integer
author_id – char(3)
isbn_number – varchar(20)
Which column should be designated at the primary key for the Book table?

a. genre
b. pages
c. author_id
d. isbn_number

3. The Book table has the following columns:


genre – varchar(20)
pages – integer
author_id – char(3)
isbn_number – varchar(20)
Which column should be designated as the foreign key for the Book table?

a. genre
b. pages
c. author_id
d. isbn_number

4. Which data type represents numbers with fractional values:

a. Integer
b. Decimal
c. Character
d. Binary
5. Which of the following is a DDL commands?

a. INSERT
b. SELECT
c. CREATE INDEX
d. UPDATE

6. Which of the following is a DML command?

a. CREATE VIEW
b. CREATE TABLE
c. INSERT
d. ALTER INDEX

7.
CREATE TABLE Invoice (
invoice_id INT NOT NULL AUTO_INCREMENT,
date DATE NOT NULL,
customer_id INT NOT NULL UNIQUE,
PRIMARY KEY (invoice_id),
FOREIGN KEY (customer_id) REFERENCES Customer (customer_id) ON DELETE
CASCADE
);
Looking at the Customer and Invoice tables and the CREATE TABLE for the Invoice table with
foreign key reference statement above, what would happen to invoices in the Invoice table that are
linked to a customer if that customer is deleted.

a. Those invoices would remain in the database.


b. Those invoices would be deleted also.
c. The Customer ID for those invoices would be changed to NULL.
d. Nothing would happen.

Customer ID (PK) Invoice ID (PK)


Customer Last Name Date
Customer First Name Customer ID (FK)
Street Address
City
State
Zip
8.
CREATE TABLE Invoice (
invoice_id INT NOT NULL AUTO_INCREMENT,
date DATE NOT NULL,
customer_id INT NOT NULL,
PRIMARY KEY (invoice_id),
FOREIGN KEY (customer_id) REFERENCES Customer (customer_id) ON DELETE
RESTRICT
);

Looking at the Customer and Invoice tables and the CREATE TABLE for the Invoice table with
foreign key reference statement above, what would happen to invoices in the Invoice table that are
linked to a customer if that customer is deleted.

a) Those customers would remain in the customer database.


b) Those invoices would be deleted also.
c) The Customer ID for those invoices would be changed to NULL.
d) The delete of the invoices would not be allowed.

Customer ID (PK) Invoice ID (PK)


Customer Last Name Date
Customer First Name Customer ID (FK)
Street Address
City
State
Zip

9.

CREATE TABLE Invoice (


invoice_id INT NOT NULL AUTO_INCREMENT,
date DATE NOT NULL,
customer_id INT NOT NULL,
PRIMARY KEY (invoice_id),
FOREIGN KEY (customer_id) REFERENCES Customer (customer_id) ON DELETE SET TO
NULL
);

Looking at the Customer and Invoice tables and the CREATE TABLE for the Invoice table with
foreign key reference statement above, what would happen to invoices in the Invoice table that are
linked to a customer if that customer is deleted.

a. Those invoices would remain in the database.


b. Those invoices would be deleted also.
c. The Customer ID for those invoices would be changed to NULL.
d. The delete of the Customer would not be allowed.

Customer ID (PK) Invoice ID (PK)


Customer Last Name Date
Customer First Name Customer ID (FK)
Street Address
City
State
Zip

10.
Which of the following are true about materialized view (Choose 2)?

a. It is a base table.
b. It is stored.
c. It must be refreshed whenever the base table changes.
d. The results are stored as a temporary table.

11.
The Customer table will have the following columns:
CustomerID—positive integer
FirstName—variable-length string with up to 50 characters
MiddleInitial—fixed-length string with 1 character
LastName—variable-length string with up to 50 characters
DateOfBirth—date
CreditLimit—positive decimal value representing a cost of up to $19,999.99 with 2 digits for cents

Write a SQL statement to create the Customer table.


Do not add any additional constraints to any column beyond what is stated.
12.
The Genre table has the following columns:
GenreCode—variable-length string, primary key
GenreDescription—variable-length string
The Book table should have the following columns:
Title—variable-length string, maximum 30 characters
GenreCode—variable-length string, maximum 5 characters
Write a SQL statement to create the Book table. Designate the GenreCode column in the Book table as a
foreign key to the GenreCode column in the Genre table.

13.
The Automobile table has the following columns:
ID—integer, primary key
Make—variable-length string
Model—variable-length string
Year—integer

A new column must be added to the Automobile table:


Column name: SafetyRating
Data type: A positive number that is less than 80 with 1 decimal space.
Write a SQL statement to add the SafetyRating column to the Automobile table

14.
The Book table has the following columns:
ID—integer, primary key
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL statement to create a view named MyBooks that contains the Title, Genre,
and Year columns for all books. Ensure your result set returns the columns in the order indicated.

15.
A database has a view named BookView.
Write a SQL statement to delete the view named BookView from the database.
16.
The Book table has the following columns:
ID—integer
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL statement to modify the Book table to make the ID column the primary key

17.
The Book table has the following columns:
ID—integer, primary key
Title—variable-length string
Genre—variable-length string
Year—integer
The YearSales table has the following columns:
Year—integer
TotalSales—bigint unsigned
Releases—integer
Write a SQL statement to designate the Year column in the Book table as a foreign key to
the Year column in the YearSales table.

18.
The Book table has the following columns:
ID—integer, primary key
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL statement to create an index named idx_year on the Year column of the Book table.

19.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
The following data needs to be added to the Book table:
Title Genre Year
The Joy Luck Club No Data 1989

Write a SQL statement to insert the indicated data into the Book table.
20.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL statement to delete the row with the ID value of 3 from the Book table.

21.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL statement to update the Year value to be 2022 for all books with a Year value of 2020.

22. Which query illustrates performing an outer join of the Book table with a different table?

a. SELECT B.Title, A.Author FROM Book B, Author A


WHERE B.AuthorID = A.AuthorID;
b. SELECT B.Title, A.Author FROM Book B
LEFT JOIN Book MB ON B.ID = MB.IF, Author A;
c. SELECT Book.Title, A.Author FROM Book B
RIGHT JOIN Author A ON B.AuthorID = A.ID;
d. SELECT B.Title, A.Author FROM Book B
INNER JOIN Author A ON B.AuthorID = A.ID;

23. Assume there are two tables, A and B.


Which rows will always be included in the result set if Table A is inner joined with Table B?
a. Only rows in Tables A and B that share the join condition
b. All rows in Table B
c. All rows in Table A
d. Only rows in Tables A and B that do not share the join condition.

24.
The database contains a table named Book.
Write a SQL query to return all data from the Book table without directly referencing any column
names.
25.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL query to retrieve the Title and Genre values for all records in the Book table with
a Year value of 2020. Ensure your result set returns the columns in the order indicated.

26.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL query to display all Title values in alphabetical order A–Z

27.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL query to output the unique Genre values and the number of books with each genre value
from the Book table as GenreCount. Sort the results by the Genre in reverse alphabetical order Z-A.
Ensure your result set returns the columns in the order indicated.

28 A)
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
The YearSales table has the following columns:
Year—integer
TotalSales—bigint unsigned
Releases—integer
Write a SQL query to display both the TotalSales and the Title(if available) for all YearSales. Ensure
your result set returns the columns in the order indicated.
28 B)
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
The YearSales table has the following columns:
Year—integer
TotalSales—bigint unsigned
Releases—integer
Write a SQL query to display both the Title and the TotalSales for all books. Ensure your result set
returns the columns in the order indicated.

28 C)
The YearSales table has the following columns:
Year—integer
TotalSales—bigint unsigned
Releases—integer
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer

Write a SQL query to display both the Title and TotalSales regardless of whether they had any sales for
all Books. Ensure your result set returns the columns in the order indicated.

29.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Cost – positive decimal value up to $9999.99

Write a SQL statement that will add $1 (for charity) to the cost of any book that costs $50 dollars or
less.

30.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL query to return how many books have a Year value of 2019.

31.
The Movie table has the following columns:
MovieID—integer, primary key
Title—variable-length string
ReleaseDate – date
Cost – integer, positive
StreamID— fixed length character

A) Write a SQL statement to pull how much the most expensive movie cost to make.

B) Write another SQL statement to pull all data for movies that were above average cost to make.

32.
The Employee table has the following columns:
EmployeeID – integer, primary key
FirstName – variable-length character string
LastName – variable-length character string
EmployeeType – variable-length character string
Salary – decimal, positive

Write a SQL statement to pull the EmployeeType and the highest salary by EmployeeType in the
Employee table.

Grade this test all or nothing like the OA does! No partial credit is given on
the OA (even in SQL coding questions.) You must score 17/25 on the OA to pass,
so try to score 90% on these practice tests & PreA, to be confident you will pass!

1. Seattle, WA 98111
USA
How many attributes are present in the address fragment?

a. 1
b. 2
c. 3
d. 4
2. The Book table has the following columns:
genre – varchar(20)
pages – integer
author_id – char(3)
isbn_number – varchar(20)
Which column should be designated at the primary key for the Book table?

a. genre
b. pages
c. author_id
d. isbn_number

3. The Book table has the following columns:


genre – varchar(20)
pages – integer
author_id – char(3)
isbn_number – varchar(20)
Which column should be designated as the foreign key for the Book table?

a. genre
b. pages
c. author_id
d. isbn_number
4. Which data type represents numbers with fractional values:

a. Integer
b. Decimal
c. Character
d. Binary
5. Which of the following is a DDL commands?

a. INSERT
b. SELECT
c. CREATE INDEX
d. UPDATE

6. Which of the following is a DML command?

a. CREATE VIEW
b. CREATE TABLE
c. INSERT
d. ALTER INDEX

7.
CREATE TABLE Invoice (
invoice_id INT NOT NULL AUTO_INCREMENT,
date DATE NOT NULL,
customer_id INT NOT NULL,
PRIMARY KEY (invoice_id),
FOREIGN KEY (customer_id) REFERENCES Customer (customer_id) ON DELETE
CASCADE
);
Looking at the Customer and Invoice tables and the CREATE TABLE for the Invoice table with
foreign key reference statement above, what would happen to invoices in the Invoice table that are
linked to a customer if that customer is deleted.

a. Those invoices would remain in the database.


b. Those invoices would be deleted also.
c. The Customer ID for those invoices would be changed to NULL.
d. Nothing would happen.

Customer ID (PK) Invoice ID (PK)


Customer Last Name Date
Customer First Name Customer ID (FK)
Street Address
City
State
Zip
8.
CREATE TABLE Invoice (
invoice_id INT NOT NULL AUTO_INCREMENT,
date DATE NOT NULL,
customer_id INT NOT NULL,
PRIMARY KEY (invoice_id),
FOREIGN KEY (customer_id) REFERENCES Customer (customer_id) ON DELETE
RESTRICT
);
Looking at the Customer and Invoice tables and the CREATE TABLE for the Invoice table with
foreign key reference statement above, what would happen to invoices in the Invoice table that are
linked to a customer if that customer is deleted.
a) Those customers would remain in the customer database.
b) Those invoices would be deleted also.
c) The Customer ID for those invoices would be changed to NULL.
d) The delete of the invoices would not be allowed.

Customer ID (PK) Invoice ID (PK)


Customer Last Name Date
Customer First Name Customer ID (FK)
Street Address
City
State
Zip
9.
CREATE TABLE Invoice (
invoice_id INT NOT NULL AUTO_INCREMENT,
date DATE NOT NULL,
customer_id INT NOT NULL,
PRIMARY KEY (invoice_id),
FOREIGN KEY (customer_id) REFERENCES Customer (customer_id) ON DELETE SET TO
NULL
);

Looking at the Customer and Invoice tables and the CREATE TABLE for the Invoice table with
foreign key reference statement above, what would happen to invoices in the Invoice table that are
linked to a customer if that customer is deleted.

a. Those invoices would remain in the database.


b. Those invoices would be deleted also.
c. The Customer ID for those invoices would be changed to NULL.
d. The delete of the Customer would not be allowed.

Customer ID (PK) Invoice ID (PK)


Customer Last Name Date
Customer First Name Customer ID (FK)
Street Address
City
State
Zip

10.
Which of the following are true about materialized view (Choose 2)?

a. It is a base table.
b. It is stored.
c. It must be refreshed whenever the base table changes.
d. The results are stored as a temporary table.

11.
The Customer table will have the following columns:
CustomerID—positive integer
FirstName—variable-length string with up to 50 characters
MiddleInitial—fixed-length string with 1 character
LastName—variable-length string with up to 50 characters
DateOfBirth—date
CreditLimit—positive decimal value representing a cost of up to $19,999, with 2 digits for cents
Write a SQL statement to create the Customer table.
Do not add any additional constraints to any column beyond what is stated.
CREATE TABLE Customer (
CustomerID INT UNSIGNED,
FirstName VARCHAR(50),
MiddleInitial CHAR(1),
LastName VARCHAR(50),
DateOfBirth DATE,
CreditLimit DECIMAL(7,2) UNSIGNED CHECK(CreditLimit <= 19999.99)
);
12.
The Genre table has the following columns:
GenreCode—variable-length string, primary key
GenreDescription—variable-length string

The Book table should have the following columns:


Title—variable-length string, maximum 30 characters
GenreCode—variable-length string, maximum 5 characters
Write a SQL statement to create the Book table. Designate the GenreCode column in
the Book table as a foreign key to the GenreCode column in the Genre table.

CREATE TABLE Book (


Title VARCHAR(30),
GenreCode VARCHAR(5),
FOREIGN KEY (GenreCode) REFERENCES Genre(GenreCode)
);
13.
The Automobile table has the following columns:

ID—integer, primary key


Make—variable-length string
Model—variable-length string
Year—integer

A new column must be added to the Automobile table:


Column name: SafetyRating
Data type: A positive number that is less than 80 with 1 decimal space.
Write a SQL statement to add the SafetyRating column to the Automobile table.

ALTER TABLE Automobile


ADD SafetyRating DECIMAL(3,1) UNSIGNED CHECK(SafetyRating < 80.0);

OR

ALTER TABLE Automobile


ADD SafetyRating DECIMAL(3,1) UNSIGNED CHECK(SafetyRating < = 79.9);
14.
The Book table has the following columns:
ID—integer, primary key
Title—variable-length string
Genre—variable-length string
Year—integer

Write a SQL statement to create a view named MyBooks that contains the Title, Genre,
and Year columns for all books. Ensure your result set returns the columns in the order indicated.

CREATE VIEW MyBooks AS


SELECT Title, Genre, Year
FROM Book;

15.
A database has a view named BookView.
Write a SQL statement to delete the view named BookView from the database.

DROP VIEW BookView;


16.
The Book table has the following columns:
ID—integer,
Title—variable-length string
Genre—variable-length string
Year—integer

Write a SQL statement to modify the Book table to make the ID column the primary key.
ALTER TABLE Book
ADD PRIMARY KEY (ID);

17.
The Book table has the following columns:
ID—integer, primary key
Title—variable-length string
Genre—variable-length string
Year—integer

The YearSales table has the following columns:


Year—integer
TotalSales—bigint unsigned
Releases—integer

Write a SQL statement to designate the Year column in the Book table as a foreign key to
the Year column in the TotalSales table.

ALTER TABLE Book


ADD FOREIGN KEY (Year) REFERENCES YearSales (Year);

18.
The Book table has the following columns:
ID—integer, primary key
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL statement to create an index named idx_year on the Year column of the Book table.

CREATE INDEX idx_year


ON Book(Year);

19.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer

The following data needs to be added to the Book table:


Title Genre Year
The Joy Luck Club No Data 1989

Write a SQL statement to insert the indicated data into the Book table.

INSERT INTO Book (Title, Genre, Year) VALUES


(‘The Joy Luck Club’, NULL, 1989);

20.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL statement to delete the row with the ID value of 3 from the Book table.

DELETE FROM Book


WHERE ID = 3;

21.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL statement to update the Year value to be 2022 for all books with a Year value of 2020.
UPDATE Book
SET Year = 2022
WHERE Year = 2020;

22. Which query illustrates performing an outer join of the Book table with a different table?
a. SELECT B.Title, A.Author FROM Book B, Author A
WHERE B.AuthorID = A.AuthorID;
b. SELECT B.Title, A.Author FROM Book B
LEFT JOIN Book MB ON B.ID = MB.IF, Author A
c. SELECT Book.Title, A.Author FROM Book B
RIGHT JOIN Author A ON B.AuthorID = A.ID
d. SELECT B.Title, A.Author FROM Book B
INNER JOIN Author A ON B.AuthorID = A.ID
This question is asking which statement illustrates an OUTER JOIN, not an INNER JOIN. The only 2
statements above that include outer joins are b and c (LEFT JOIN and RIGHT JOIN).
B is an invalid statement, so C has to be the answer. Please review the JOINS PPT to help you!

23.
Assume there are two tables, A and B.
Which rows will always be included in the result set if Table A is inner joined with Table B?
a. Only rows in Tables A and B that share the join condition
b. All rows in Table B
c. All rows in Table A
d. Only rows in Tables A and B that do not share the join condition.

24.
The database contains a table named Book.
Write a SQL query to return all data from the Book table without directly referencing any column
names.

SELECT * FROM Book;


25.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL query to retrieve the Title and Genre values for all records in the Book table with
a Year value of 2020. Ensure your result set returns the columns in the order indicated.
SELECT Title, Genre
FROM Book
WHERE Year = 2020;
26.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL query to display all Titles in alphabetical order from A–Z.
This question is testing to see if the student knows how to use the ORDER BY clause. Here is the
general syntax:

And here is the correct answer.


SELECT Title
FROM Book
ORDER BY Title ASC;

27.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL query to output the unique Genre values and the number of books with each genre value
from the Book table as GenreCount. Sort the results by the Genre in reverse alphabetical order Z-A.
Ensure your result set returns the columns in the order indicated.

In this case you are being asked to count the number of Movies having each type of Genre. For this
reason, you must use GROUP BY to group all moves with each Genre together and then do a count.
The attribute you are grouping on must be listed first.

SELECT DISTINCT Genre, COUNT(*) AS GenreCount


FROM Book
GROUP BY Genre
ORDER BY Genre DESC;
Please take a look at these resources:

GROUP BY
COUNT

28 A)
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string Book YearSales
Year—integer Stipulation
The YearSales table has the following columns:
Year—integer
TotalSales—bigint unsigned
Releases—integer

Write a SQL query to display both the TotalSales and the Title (if available) for all YearSales. Ensure
your result set returns the columns in the order indicated.

SELECT YearSales.TotalSales, Book.Title


FROM Book
RIGHT JOIN YearSales
ON Book.Year = YearSales.Year;

Here, you must have a RIGHT JOIN because the stipulation “if available” comes from the left table,
and TotalSales for ALL YearSales (RIGHT Table.)
Review the JOINS and Aggregate Functions PPT in Slide Show Mode.

28 B)
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string Book YearSale
Year—integer s
The YearSales table has the following columns:
Year—integer
TotalSales—bigint unsigned
Releases—integer
Write a SQL query to display both the Title and the TotalSales for all books. Ensure your result set
returns the columns in the order indicated.

SELECT Book.Title, YearSales.TotalSales


FROM Book
INNER JOIN YearSales
ON Book.Year = YearSales.Year;

This one is an INNER JOIN because there are no stipulations (if available/regardless of/include
nulls). It really shouldn’t say for ALL books, but it’s what Zybooks does! It should say for ANY Books
or ANY YearSales. We are trying to get this fixed with the publisher of Zybooks. Please review the
JOINS and Aggregate Functions PPT in Slide Show Mode for more in-depth explanations and
practice.

28 C)
The YearSales table has the following columns:
Year—integer
TotalSales—bigint unsigned
Releases—integer YearSales Book
The Book table has the following columns: Stipulation
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer

Write a SQL query to display both the Title and TotalSales regardless of whether they had any sales
for all Books. Ensure your result set returns the columns in the order indicated.

SELECT Book.Title, YearSales.TotalSales,


FROM YearSales
RIGHT JOIN Book
ON YearSales.Year = Book.Year;

Here, you must have a RIGHT JOIN because of the stipulation “regardless of whether they had any
sales” comes from the LEFT table (stipulation so bring some of these), and Title for ALL BOOKS.
Review the JOINS and Aggregate Functions PPT in Slide Show Mode.

29.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Cost – positive decimal value up to $9999.99.

Write a SQL query that will add $1 (for charity) to the cost of any book that costs $50 dollars or less.

UPDATE Book
SET Cost = Cost + 1
WHERE Cost <= 50;

30.
The Book table has the following columns:
ID—integer, primary key, auto_increment
Title—variable-length string
Genre—variable-length string
Year—integer
Write a SQL query to return how many books have a Year value of 2019.

SELECT COUNT(*)
FROM Book
WHERE Year = 2019;

31.
The Movie table has the following columns:
MovieID—integer, primary key
Title—variable-length string
ReleaseDate – date
Cost – integer, positive
StreamID— fixed length character

A) Write a SQL statement to pull how much the most expensive movie cost to make.

SELECT MAX(Cost)
FROM Movie;
B) Write another SQL statement to pull all data for movies that were above average cost to make.

SELECT *
FROM Movie
WHERE Cost >
(SELECT AVG(Cost) FROM Movie);

This is a subquery and must be used because you cannot put an Aggregate Function in a
WHERE clause directly. You must use a subquery so look for ‘below average’ or ‘above average’
in the question.

32.
The Employee table has the following columns:
EmployeeID – integer, primary key
FirstName – variable-length character string
LastName – variable-length character string
EmployeeType – variable-length character string
Salary – decimal, positive

Write a SQL statement to pull the EmployeeType and the highest salary by EmployeeType in the
Employee table:

SELECT EmployeeType, MAX(Salary)


FROM Employee
GROUP BY EmployeeType;
Here is what the result could look like:

Employee Type Max(Salary)


Associate 60000
Supervisor 80000
Manager 100000
Director 120000

You might also like