Question

Given: Create table Book ( Book_id integer, Book_title varchar(50), Author varchar(50), Publish_date date, Type varchar(30), Edition...

Given:

Create table Book (

Book_id integer,

Book_title varchar(50),

Author varchar(50),

Publish_date date,

Type varchar(30),

Edition number,

Quantity number,

Primary key (Book_id)

);

insert into Book values (1,'The Old Man and the Sea','Hemingway' ,date '1978-1-1','hardcopy',3,2);

insert into Book values (2,'The Old Man and the Sea','Hemingway' ,date '1979-1-1','hardcopy',4,1);

insert into Book values (3,'The Old Man and the Sea','Hemingway' ,date '1980-1-1', 'hardcopy',5,10);

insert into Book values (4,'A Farewell to Arms','Hemingway' ,date '1986-1-1','hardcopy',2,18);

insert into Book values (5,'For Whom the Bell Tolls','Hemingway' ,date '1980-1-1','hardcopy',8,1);

insert into Book values (6,'The Great Gatsby','Fitzgerald' ,date '1978-1-1', 'hardcopy',2,3);

insert into Book values (7,'This Side of Paradise','Fitzgerald' ,date '1973-1-1','hardcopy',1,1);

insert into Book values (8,'Tender is the Night','Fitzgerald' ,date '1979-1-1', 'hardcopy',6,18);

insert into Book values (9,'The Age of Innocence','Wharton' ,date '2012-1-1','hardcopy',3,5);

create table customer (

customer_id integer,

customer_name varchar(50),

primary key (customer_id));

insert into customer values (1,'John');

insert into customer values (2, 'Mary');

insert into customer values (3, 'Jake');

insert into customer values (4, 'Sam');

create table loan_event (

loan_id integer,

customer_id integer,

loan_date date,

payment number,

primary key (loan_id),

foreign key (customer_id) references customer(customer_id));

insert into loan_event values (1,1, date '2016-4-1', 0);

insert into loan_event values (2,1, date '2016-3-1', 3.5);

insert into loan_event values (3,1, date '2016-2-1', 0.5);

insert into loan_event values (4,2, date '2016-1-1', 0);

insert into loan_event values (5,3, date '2016-4-11', 0);

create table loan_detail (

loan_id integer,

book_id integer,

due_date date,

return_date date,

primary key(loan_id, book_id),

foreign key(loan_id) references loan_event(loan_id),

foreign key (book_id) references book(book_id));

insert into loan_detail values (1,1, date '2016-4-10', date '2016-4-5');

insert into loan_detail values (1,4, date '2016-4-10', date '2016-4-5');

insert into loan_detail values (1,5, date '2016-4-10', date '2016-4-10');

insert into loan_detail values (2,2, date '2016-3-10', date '2016-3-15');

insert into loan_detail values (3,3, date '2016-2-10', date '2016-3-15');

insert into loan_detail values (4,6, date '2016-1-10', date '2016-2-15');

insert into loan_detail values (4,7, date '2016-1-10', date '2016-2-15');

insert into loan_detail values (4,8, date '2016-1-10', date '2016-2-15');

insert into loan_detail values (5,9, date '2016-4-10', date '2016-4-15');

Give Sql Oracle statements for the following:

List the titles of books published after January 1, 1978 and contain the word ‘Sea’ in the title.

Update the Quantity of all books published before January 1, 1975 to 0.

Find out the average quantity of books published before January 1, 1980.

List the number of books published by each author. Please return the number of books and author name. (Here each edition of a book is considered one book)

List the names of authors who have published more than one book in the database. (Here each edition of a book is considered one book)

Return the IDs of the loans made by a customer named ‘John’.

Return the loan_date of the loans made by ‘John’.

Return the names of the customers and the IDs of their loans, including those who do not have loans.

List the titles of all the books borrowed by ‘John’.

List the names of the customers and their total payment. Hint: 1) Total payment of a member can be computed as the sum of the payments for all the loans made by that customer. 2) Use join and group by.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

select * from book where Publish_date >'1978-1-1' and Book_title LIKE '%Sea%';

UPDATE book SET Quantity= 0 WHERE Publish_date<'1975-1-1';

select AVG(Quantity) from book where Publish_date<'1980-1-1';

select Quantity number,Autor from book;

select Author from book where COUNT(Quantity number)>1;


select loan_id from loan_event,customer where customer.customer_id=loan_event.customer_id and customer.customer_name='john';

select loan_date from loan_event,customer where customer.customer_id=loan_event.customer_id and customer.customer_name='john';

select loan_event.loan_id,customer.customer_id from loan_event,customer where customer.customer_id=loan_event.customer_id ;

select book.Book_title from book,customer,loan_detail where customer.customer_id = loan_detail.customer_id and
loan_detail.book_id = book.Book_id;

SELECT customer.customer_name,
SUM(loan_event.paymentnumber)
FROM customer,loan_event
WHERE customer.customer_id=loan_event.customer_id
GROUP BY customer.customer_name,loan_event.paymentnumber;

Add a comment
Know the answer?
Add Answer to:
Given: Create table Book ( Book_id integer, Book_title varchar(50), Author varchar(50), Publish_date date, Type varchar(30), Edition...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CREATE TABLE DEPT ( DEPTNO INTEGER NOT NULL, DNAME VARCHAR(14), LOC VARCHAR(13), PRIMARY KEY (DEPTNO)); INSERT...

    CREATE TABLE DEPT ( DEPTNO INTEGER NOT NULL, DNAME VARCHAR(14), LOC VARCHAR(13), PRIMARY KEY (DEPTNO)); INSERT INTO DEPT VALUES (10,'SPORTS','NEW YORK'); INSERT INTO DEPT VALUES (20,'HOME','DALLAS'); INSERT INTO DEPT VALUES (30,'OUTDOOR','CHICAGO'); INSERT INTO DEPT VALUES (40,'CLOTHING','BOSTON'); CREATE TABLE EMP ( EMPNO INTEGER NOT NULL, ENAME VARCHAR(10), JOB VARCHAR(9), MGR INTEGER, SAL FLOAT, COMM FLOAT, DEPTNO INTEGER NOT NULL, FOREIGN KEY (DEPTNO) REFERENCES DEPT (DEPTNO), FOREIGN KEY (MGR) REFERENCES EMP(EMPNO), PRIMARY KEY (EMPNO)); INSERT INTO EMP VALUES (7839,'KING','PRESIDENT',NULL, 5000,NULL,10); INSERT INTO...

  • please answer 56789 CREATE TABLE ALLDRINKS(   /* All legal drinks */ DRINK       VARCHAR(30)   NOT NULL,  ...

    please answer 56789 CREATE TABLE ALLDRINKS(   /* All legal drinks */ DRINK       VARCHAR(30)   NOT NULL,   /* Drink name   */    CONSTRAINT DRINKNAME_PKEY PRIMARY KEY(DRINK) ); CREATE TABLE DRINKERS ( /* All drinkers */ DRINKER   VARCHAR(30)   NOT NULL,    CONSTRAINT DRINKERS_PKEY PRIMARY KEY (DRINKER)); CREATE TABLE LOCATED(   /* Pubs have locations */ PUB           VARCHAR(30)   NOT NULL,   /* Pub name   */ STREET       VARCHAR(30)   NOT NULL,   /* Street name   */ BLDG_NO       DECIMAL(4)   NOT NULL,   /* Building number   */...

  • MYSQL Questions: 1.For every author, display the number of books written by that author that is...

    MYSQL Questions: 1.For every author, display the number of books written by that author that is carried by Henry Books. Display the author number as ‘Author Number’, author name concatenated (first last) as ‘Author Name’, and the total number of books written by the author as ‘Number of Titles by Author’. List in descending order by author number. Limit the output to 10 rows. Insert your snip of the query and resultset together here. 2.Using a function, what are the...

  • 1. Create the following tables and establish relationships. All fields are Varchar except parts price and date. Invoice Invoice_ID Customer_ID Part_Number Date...

    1. Create the following tables and establish relationships. All fields are Varchar except parts price and date. Invoice Invoice_ID Customer_ID Part_Number Date Customer Customer_ID Customer_Name Customer_Address Customer_Telephone Parts Part_Number Part_Description Parts_Price Supplier_ID Supplier Supplier_ID Supplier_Name Supplier_Address Sales_Rep 10 points 2. Populate data (you make it up) use at least one insert into query for each table the rest you can enter in grid view. 10 points (queries) 3. Update one of the supplier’s address. 4. Add a field named supplier...

  • SQL I have a database CREATE TABLE vendor ( vid CHAR(2) NOT NULL, vname VARCHAR(25) NOT...

    SQL I have a database CREATE TABLE vendor ( vid CHAR(2) NOT NULL, vname VARCHAR(25) NOT NULL, PRIMARY KEY (vid) ); CREATE TABLE category ( catid CHAR(2) NOT NULL, catname VARCHAR(25) NOT NULL, PRIMARY KEY (catid) ); CREATE TABLE product ( pid CHAR(3) NOT NULL, pname VARCHAR(25) NOT NULL, price NUMERIC (7,2) NOT NULL, vid CHAR(2) NOT NULL, categoryid CHAR(2) NOT NULL, PRIMARY KEY (pid)); CREATE TABLE region ( rid CHAR NOT NULL, rname VARCHAR(25) NOT NULL, PRIMARY KEY (rid)...

  • Problem 4 (DOM operations - 30 points): Consider the Python code snippet bookstore.py for DOM operation,...

    Problem 4 (DOM operations - 30 points): Consider the Python code snippet bookstore.py for DOM operation, some basic methods and properties and an xml file on bookstore which we discussed this week. Wite two func- tions; First, write a recursive Python function get_text(elm) to extract all the text of a dom tree pointed by elm. For example, get_text(elm), where elm=<bookstore>, will return [[u'Emacs User Manual', u'Richard Stallman', u'1980', u'12.00'], [u'Timeline', u'Michael Chricton', u'1999', u'15.00'], [u'Catch 22', u'Joseph Heller', u'1961', u'20.00'],...

  • MYSQL: Question: 1.Using a function, what are the lowest price books found in paperback? Only return...

    MYSQL: Question: 1.Using a function, what are the lowest price books found in paperback? Only return the lowest price books. Display the book code as ‘Book Code’, the book title as ‘Title’, author name concatenated (first last) as ‘Author Name’ and price as ‘Price’. Insert your snip of the query and resultset together here. 2. Display the number of publishers by city.   Display the city as ‘City’ and the number of publishers in that city as ‘Number of Publishers’. Insert...

  • Oracle only database: DROP TABLE ORDERITEMS; DROP TABLE Orders; DROP TABLE BOOKAUTHOR; DRO...

    oracle only database: DROP TABLE ORDERITEMS; DROP TABLE Orders; DROP TABLE BOOKAUTHOR; DROP TABLE BOOKS; DROP TABLE PROMOTION; DROP TABLE AUTHOR; DROP TABLE CUSTOMERS; DROP TABLE PUBLISHER; CREATE TABLE Customers ( Customer# NUMBER(4), LastName VARCHAR2(10) NOT NULL, FirstName VARCHAR2(10) NOT NULL, Email VARCHAR(40), Address VARCHAR2(20), City VARCHAR2(12), State VARCHAR2(2), Zip VARCHAR2(5), Referred NUMBER(4), Region CHAR(2), CONSTRAINT customers_customer#_pk PRIMARY KEY(customer#) ); INSERT INTO CUSTOMERS VALUES (1001, 'MORALES', 'BONITA', '[email protected]', 'P.O. BOX 651', 'EASTPOINT', 'FL', '32328', NULL, 'SE'); INSERT INTO CUSTOMERS VALUES...

  • How would you use this stored procedure to change the price of any copy of book 0180 whose format...

    How would you use this stored procedure to change the price of any copy of book 0180 whose format is paperback to $10.95? using MYSQL 8.0 Command line Client This is the database script for the homework above CREATE DATABASE HENRY; USE HENRY; CREATE TABLE AUTHOR (AUTHOR_NUM DECIMAL(2,0) PRIMARY KEY, AUTHOR_LAST CHAR(12), AUTHOR_FIRST CHAR(10) ); CREATE TABLE BOOK (BOOK_CODE CHAR(4) PRIMARY KEY, TITLE CHAR(40), PUBLISHER_CODE CHAR(3), TYPE CHAR(3), PRICE DECIMAL(4,2), PAPERBACK CHAR(1) ); CREATE TABLE BRANCH (BRANCH_NUM DECIMAL(2,0) PRIMARY KEY,...

  • Create SQL statements based on the given tables: Code to create the tables: CREATE DATABASE LAB...

    Create SQL statements based on the given tables: Code to create the tables: CREATE DATABASE LAB4DB; USE LAB4DB; CREATE TABLE CUSTOMER ( CUS_CODE int primary key, CUS_LNAME varchar(15), CUS_FNAME varchar(15), CUS_INITIAL varchar(1), CUS_AREACODE varchar(3), CUS_PHONE varchar(8), CUS_BALANCE float(8) ); INSERT INTO CUSTOMER VALUES('10010','Ramas','Alfred','A','615','844-2573','0'); INSERT INTO CUSTOMER VALUES('10011','Dunne','Leona','K','713','894-1238','0'); INSERT INTO CUSTOMER VALUES('10012','Smith','Kathy','W','615','894-2285','345.86'); INSERT INTO CUSTOMER VALUES('10013','Olowski','Paul','F','615','894-2180','536.75'); INSERT INTO CUSTOMER VALUES('10014','Orlando','Myron','','615','222-1672','0'); INSERT INTO CUSTOMER VALUES('10015','O''Brian','Amy','B','713','442-3381','0'); INSERT INTO CUSTOMER VALUES('10016','Brown','James','G','615','297-1228','221.19'); INSERT INTO CUSTOMER VALUES('10017','Williams','George','','615','290-2556','768.93'); INSERT INTO CUSTOMER VALUES('10018','Farriss','Anne','G','713','382-7185','216.55'); INSERT INTO CUSTOMER VALUES('10019','Smith','Olette','K','615','297-3809','0'); /*...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT