Question

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:

  1. 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.
  2. 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 day of the month, like "January 3, 2011."
  3. Write a query that shows the title(s) of the book most frequently purchased by the customers in the database. Use the quantity column from the orderitems table to find the book most frequently purchased.
  4. Write a query that displays the names of the customers who purchased the book with the highest retail price in the database. Capitalize the first and last names.
  5. Write a query that displays the first name and last name of each author along with the number of books he or she has written. Capitalize the first and last names.

--1

SELECT title, isbn, cost, TO_CHAR(retail, '$999.99') AS retail

FROM books

WHERE cost <

(SELECT AVG (cost)

FROM books);

--2

SELECT title

TO_CHAR(pubdate, 'Month DD, YYYY') "Publication Date"

FROM books;

--3

SELECT title

FROM books

WHERE isbn = (select isbn from orderitems HAVING SUM (quantity) = (select MAX(SUM(quantity))

FROM orderitems

GROUP BY isbn);

--4

SELECT INITCAP (firstname) AS "First Name", INITCAP (lastname) AS "Lastname"

FROM customers

JOIN orders Using (customer#)

JOIN orderitems Using (Order#)

JOIN books USING (isbn)

WHERE retail =

(SELECT MAX(retail) FROM books;

--5

SELECT fname, lname, booknum AS "Number of Books"

FROM author join

(SELECT COUNT (isbn), booknum, authorid

FROM bookauthor

GROUP BY authorid)

USING (authorid);

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

Yes, the SQL queries look fine to me. Please run these in the database one by one and check if you are getting the desired output. You might see 2 issues:

1. issues with some syntax or any other error before it generates any output.

In this case please post the error message in the comment section, I can take a look and let you know for the corrections that may need. Looking at the data, it looks like fine and , you should not receive any error.

2. You may not get desired output as needed:

If so, please post actual output you need and the output you are getting. I can take a look and suggest you any changed you need.

best of luck!

Add a comment
Know the answer?
Add Answer to:
Do these codes look right for the following 5 statements. This is using Oracle SQL: Write...
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
  • I need to write a SQL query that displays the first name and last name of...

    I need to write a SQL query that displays the first name and last name of each author along with the number of books he or she has written. Capitalize the first and last names. AUTHOR table: AUTHORID, LNAME, FNAME BOOKAUTHOR table: ISBN, AUTHORID BOOKS table: ISBN, TITLE, PUBDATE, PUBID, COST, RETAIL, DISCOUNT, CATEGORY

  • I need to create a SQL query that displays the names of the customers who purchased...

    I need to create a SQL query that displays the names of the customers who purchased the book with the highest retail price in the database. Also I need to capitalize the first and last names. CUSTOMERS Table: CUSTOMER#, LASTNAME, FIRSTNAME, ADDRESS, CITY, STATE, ZIP, REFERRED, REGION, EMAIL ORDERS Table: ORDER#, CUSTOMER#, ORDERDATE, SHIPDATE, SHIPSTREET, SHIPCITY, SHIPSTATE, SHIPZIP, SHIPCOST ORDERITEMS Table: ORDER#, ITEM#, ISBN, QUANTITY, PAIDEACH

  • Please help me on the SQL queries, thank you so much. Write a query to display the title and publisher as well as the p...

    Please help me on the SQL queries, thank you so much. Write a query to display the title and publisher as well as the publisher contact for each book using JOIN...USING clause. Write a query to show the first and last names of customers who have ordered cooking books. Use the WHERE clause to join the tables. Write a query to show the title, cost and ISBN of each book in the books table. If the book has been ordered,...

  • In this hands-on project, you will create an application that allows the user to connect to...

    In this hands-on project, you will create an application that allows the user to connect to a database and query the database. Write a Java query application that allows the user to connect to the books database and query the books database. Provide the following predefined queries: Select all authors from the Authors table Select a specific author and list all books for that author. Include each book’s title, year and ISBN. Display the appropriate data for each query. Given...

  • SQL query QUESTION 34 Write a SQL statement that shows the months between orderdate and pubdate...

    SQL query QUESTION 34 Write a SQL statement that shows the months between orderdate and pubdate for order# 1004. Make sure to truncate any decimal points using the trunc function - hint: see page 373 of the book. T T Dararanh Enter SQL Statement Statement SELECT title, TRUNC (MONTHS_BETWEEN (orderdate, pubdate),0) ATHS FROM books JOIN orderitems USING (isbn) JOIN orders USING (order#) WHERE orderi = 1004; | DeMS Output QONA Output Results Script Output Explain 9 Autotrace Results: 3 TITLE...

  • Which of the following queries contains a non-equality join? a. SELECT title, authorid FROM books, bookauthor...

    Which of the following queries contains a non-equality join? a. SELECT title, authorid FROM books, bookauthor WHERE books.isbn = bookauthor.isbn AND retail > 20; b. SELECT title, name FROM books JOIN publisher USING (pubid); c. SELECT title, gift FROM books, promotion WHERE retail >= minretail AND retail <= maxretail; d. none of the above

  • Write the following SQL statements in Microsoft Access by using the Books database from Week 2...

    Write the following SQL statements in Microsoft Access by using the Books database from Week 2 Assignment 2. Once complete, copy and paste the SQL statements in a Microsoft Word document: Write SQL statements: To update the publisher name from READ WITH US to READ FOR US To verify the updated name field for the publisher with ID 6 To make the following updates to the Publisher table (be careful with WHERE): Make Contact="John Travolta" for publisher with ID number...

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

  • NEED DONE ASAP POSTED 3 TIMES HIGHKEY Suppose you have the task of defining and setting up a relational database of books and authors. Some attributes (columns) of possible interest include:  last nam...

    NEED DONE ASAP POSTED 3 TIMES HIGHKEY Suppose you have the task of defining and setting up a relational database of books and authors. Some attributes (columns) of possible interest include:  last name of author,  first name, authorID, book title, book ISBN number, book category, publication date, and perhaps others. In an early (basic) version of the system, we’ll assume thateach book can have only one author, but each author can write many books.    a) if an index is not...

  • Given the following table structure, write the SQL code to display all the first and last...

    Given the following table structure, write the SQL code to display all the first and last names of the individuals that have a last name that begins with the letter 'M! CREATE TABLE Persons Personi int LastName varchar(80). FirstName varchar(80). Address varchar(125). State char(2) Given the following table structure, write the SQL code to display all the first and last names of the individuals that have a last name that does not contain the letter 'S: CREATE TABLE Persons PersonlDint,...

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