Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

create table books (book_id int primary key, title varchar(20) NOT NULL, author_last_name varchar(20) NOT NULL, author_first_name varchar(20) NOT NULL, rating char(1) check(rating in (1,2,3))); create

create table books

(book_id int primary key,

title varchar(20) NOT NULL,

author_last_name varchar(20) NOT NULL,

author_first_name varchar(20) NOT NULL,

rating char(1) check(rating in (1,2,3)));

create table patrons

(patron_id int primary key,

last_name varchar(20),

first_name varchar(20) NOT NULL,

street_address varchar(20),

city varchar(10),

zip char(7)

DOB date,

LAST_MODIFIED SYSDATE

MODIFIED_BY archer(20));

create table transactions

(transaction_id int primary key,

patron_id int,

book_id int,

transaction_date DATE,

transaction_type varchar(1),

CONSTRAINT FK_patrons FOREIGN KEY (patron_id)

REFERENCES patrons(patron_id),

CONSTRAINT FK_books FOREIGN KEY (book_id)

REFERENCES books(book_id));

CREATE SEQUENCE patron_customers_seq

START WITH 1000

INCREMENT BY 1;

CREATE SEQUENCE book_customers_seq

START WITH 1000

INCREMENT BY 1;

CREATE SEQUENCE transaction_customers_seq

START WITH 1000

INCREMENT BY 1;

Solve these queries from above data

  1. Write SQL to list all patrons and their number of transactions for each transaction type. Include all patrons even if they do not have transactions.
  2. Write SQL to list the books with the word database or data base or databases in their title. Make your search case insensitive. Print the authors last name (mixed case) and the title. Sort the results by the rating.
  3. Write a join command to display all the patrons with at least one book issued to them.
  4. Write SQL to list all the books (book ids and first 10 characters of the title) and their total number of transactions in 2020. Include all books even if they have no transactions (count should be 0). Sort the results by the most popular book (the book with the most transactions).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

ISBN: 0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

Is there a clear hierarchy of points in my outline?

Answered: 1 week ago

Question

6. Be able to choose and prepare a training site.

Answered: 1 week ago