Question

Introduction to Oracle 12c SQL and DB concepts: books ( book_id, title, author_last_name, author_first_name, rating) patrons...

Introduction to Oracle 12c SQL and DB concepts:

books ( book_id, title, author_last_name, author_first_name, rating)

patrons (patron_id, last_name, first_name, street_address, city_state_zip, location)

transactions (transaction_id, patron_id, book_id, transaction_date, transaction_type)

*Book_Id, Patron_id and Transaction_id are primary keys. Patron_id and book_id in transactions table are foreign keys.

Possible values for the transaction type are 1 = checking out , 2 = returning 3 = placing a hold.

  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 all the books (book ids and first 10 characters of the title) and their total number of transactions in 2013. 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).
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1:

select a.last_name,b.type1,(select count(*) from patrons left join transactions on patrons.patron_id=transactions.patron_id where patrons.patron_id=a.patron_id) as count from patrons a,(select distinct(transaction_type) as type1 from transactions) b order by a.last_name;

Output:

Answer 2:

select substr(Title,0,10),(select count(*) from transactions where book_id=books.BOOK_ID and to_char(to_date(TRANSACTION_DATE,'YYYY-MM-DD') , 'YYYY')='2013')as count from books;

Add a comment
Know the answer?
Add Answer to:
Introduction to Oracle 12c SQL and DB concepts: books ( book_id, title, author_last_name, author_first_name, rating) patrons...
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
  • Oracle 12c Based upon the contents of the BOOKS table, which of the following SQL statements...

    Oracle 12c Based upon the contents of the BOOKS table, which of the following SQL statements will display the retail price for two copies of each book currently in inventory?" SELECT * FROM books; SELECT title, retail+retail FROM books; SELECT title, retail^2 FROM books; none of the above

  • Do these codes look right for the following 5 statements. This is using Oracle SQL: Write...

    Do these codes look right for the following 5 statements. This is using Oracle SQL: Write a query that displays the title, ISBN, and wholesale cost of books whose wholesale cost is more than the average of all books. Format the retail price with dollars and cents. Write a query that displays the title and publication date of the oldest book in the BOOKS table. Format the date with the complete name of the month and a comma after the...

  • 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...

  • Part I. Create a library check-out database using Microsoft SQL Server that stores data about books,...

    Part I. Create a library check-out database using Microsoft SQL Server that stores data about books, patrons, and the check-out process. Books (BookID, BookName, Author, YearPublished) Patrons (PatronsID, PatronsName, PatronsAddress, PatronsBirthday) CheckInOut (TransactionID, PatronID, BookID, CheckOutDate, NumDay, ReturnDate, Late, Fees, Paid) - the NumDay field contains the number of days patrons can keep the book, if the return date is over the number of day, then the Late field will have a Y value and a fee of $1.00 per...

  • The primary keys are underlined. The foreign keys are denoted by asterisks (*). Description of the...

    The primary keys are underlined. The foreign keys are denoted by asterisks (*). Description of the schema: • person — keeps track of the people who borrow books from the library. The attributes contain personal and contact information. • author — keeps track of personal information about authors. • publisher — keeps track of the publisher information. To keep it simple, most of the attributes have been truncated in the sample database. 1 trivial dependencies are things like X→X or...

  • In this assignment you will implement software for your local library. The user of the software...

    In this assignment you will implement software for your local library. The user of the software will be the librarian, who uses your program to issue library cards, check books out to patrons, check books back in, send out overdue notices, and open and close the library. class Calendar We need to deal with the passage of time, so we need to keep track of Java. Declare this variable as private int date within the class itself, not within any...

  • If possible please just send the SQL statement. Thank you Each question within deliverable 3 must begin on a new page and be sure to document the question as the title of each item at the top o...

    If possible please just send the SQL statement. Thank you Each question within deliverable 3 must begin on a new page and be sure to document the question as the title of each item at the top of each page. Also, using a 12-point font, include the SQL statement and then provide a screen shot of each query. The screen shots must include both the SQL statement and the results for each item below based on the data entered in...

  • Description 1. This project will create a base account class that has the members: std::string account_code;...

    Description 1. This project will create a base account class that has the members: std::string account_code; std::string first_name; std::string last_name; double balance; Provide a constructor that initializes ALL members in its initialization list with data passed in as arguments to the constructor. Provide any accessor functions you may need (e.g. to get the account code and balance and to set the balance). In addition, include two pure virtual functions that look like the following: virtual void monthly_update() = 0; virtual...

  • Overview This lab provides you the opportunity to insert and update data with the use of SQL comm...

    Overview This lab provides you the opportunity to insert and update data with the use of SQL commands. The lab will utilize the FLIX2YOU problem, the current schema. In order to start this lab, you must have successfully completed Lab # 6. In Lab # 6, you executed a script that was provided to you. This script created 7 of the FLIX2YOU tables as documented in the Entity Relationship Diagram in the FLIX2YOU problem document. The second part of lab...

  • 1) 1) Goods in transit are automatically included in inventory regardless of whether title has passed...

    1) 1) Goods in transit are automatically included in inventory regardless of whether title has passed to the buyer. A) True B) False 2) 2) An advantage of FIFO is that it assigns the most recent costs to cost of goods sold, and does a better job of matching current costs with revenues on the income statement. A) True B) False 3) 3) Errors in the period-end inventory balance only affect the current period's records and financial statements. A) True...

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