Question

need help fixing this code. also need a screenshot of it running thank you /* Creating...

need help fixing this code.
also need a screenshot of it running
thank you

/* Creating table. */
CREATE TABLE HOM(story_name varchar (255), [user] char(50), age int, reading_counts int NOT NULL, CONSTRAINT Story_User PRIMARY KEY (story_name,[user]));
INSERT INTO HOM VALUES ('Humpty Dumpty', 'Andrea', 5, 10);
INSERT INTO HOM VALUES ('Wheels on the Bus', 'Simon', 3, 15);
INSERT INTO HOM VALUES ('Baa Baa Black Sheep', 'Leo', 7, 4);
INSERT INTO HOM VALUES ('Jack and Jill', 'James', 4, 11);
INSERT INTO HOM VALUES ('Three Blind Mice', 'Leslie', 6, 12);
INSERT INTO HOM VALUES ('Humpty Dumpty', 'Simon', 3, 8);
INSERT INTO HOM VALUES ('Three Blind Mice', 'Andrea', 5, 7);
INSERT INTO HOM VALUES ('Wheels on the Bus', 'Andrea', 5, 11);
/* View table.*/
SELECT * FROM HOM;

/* Generates most popular book*/

SELECT * FROM HOM
INNER JOIN
(SELECT DISTINCT [user], MAX(reading_counts) AS Max_reads FROM HOM GROUP BY [user]) b
ON HOM.[user] = b.[user]
AND HOM.reading_counts = b.reading_counts;

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

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

This demonstration is using SQL Server 2014. Table is created in SQL Server Management Studio (SSMS). Below is the screen in SSMS for Table HOM.

SOLQuery1.sql- NAGESH-PC.Demo (NAGESH-PCNagesh (56))- Microsoft SQL Server Management Studio File Edit View Query Project Debug Tools Window Help Demo SQLQuery1.s N...SH-PCNagesh (56))* X 曰use Demo; /* Creating table. * CREATE TABLE HOM( story_name varchar (255), [user] char(5e), age int, reading_counts int NOT NULL, CONSTRAINT Story_User PRIMARY KEY (story_name, [user]) INSERT INTO HOM VALUES (Humpty Dumpty, Andrea, 5, 10); INSERT INTO HOM VALUES (Wheels on the Bus Simon 3, 15) INSERT INTO HOM VALUES (Baa Baa Black Sheep, Leo, 7, 4); INSERT INTO HOM VALUES (Jack and Jill, James, 4, 11); INSERT INTO HOM VALUES (Three Blind Mice, Leslie, 6, 12); INSERT INTO HOM VALUES (Humpty Dumpty, Simon, 3, 8); INSERT INTO HOM VALUES (Three Blind Mice Andrea, 5, 7); INSERT INTO HOM VALUES (Wheels on the Bus, Andrea, 5, 11); /* View table.*/ SELECTFROM HOM 100 % ■Results Messages user age reading counts story_name 1 Baa Baa Black Sheep Leo 7 4 2 Humpty Dumpty 3 Humpty Dumpty 4 Jack and Jill 5 Three Blind Mice 6 Three Blind Mice Leslie 6 12 7 Wheels on the Bus Andrea 5 11 8 Wheels on the Bus Simon 315 Andrea 5 10 Simon 3 8 James 4 11 Andrea 5 7 Query executed successfully

SQL Query :

/* Generates most popular book*/

select story_name,sum(reading_counts) As Max_reads
from HOM
group by story_name order by Max_reads desc
offset 0 rows
fetch next 1 rows only;

Screen in SSMS :

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
need help fixing this code. also need a screenshot of it running thank you /* Creating...
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
  • Using Oracle database Need help getting the JAVA code for the queries and the rest of...

    Using Oracle database Need help getting the JAVA code for the queries and the rest of the instructions. Need the table provided converted and fulfil  the requirements. . For this project - you will be writing a program (you may choose whatever programming language you want) to read in your database tables from Lab 5, and then print out the contents of each of the tables. Additionally, you must print at least one query each with the following clauses: *JOIN (any...

  • Need a PHP code that has a box to type in that allows the user to...

    Need a PHP code that has a box to type in that allows the user to put the information through the PHP site to the database for the following categories: INT, First name, Last name, Sex. Once injected it needs to echo to the page to show the table of all entries. The code below is how far I got with it. MySQL: add a row and query $link = mysql_connect('stewcraw.dotstermysql.com', 'prof', '3632password'); if (!$link) { die('Could not connect: '...

  • I need help in SQL management studio please. Question: Create the same query as query 5,...

    I need help in SQL management studio please. Question: Create the same query as query 5, but only include artists if they have 'Pop' Genre. Previous question: Create a list of all composers and artists in your database. Include two columns in your record set (the names of the returned columns are in brackets): 'Composer/Artist Name' and 'Type' (which will indicate whether your results are from the composer or artist table). Order by 'Composer/Artist Name'. This is the answer for...

  • I need help with the following SQL query for a company database (script given below). The...

    I need help with the following SQL query for a company database (script given below). The name of the Department. The number of employees working in that department. The number of different projects controlled by this department. The name of the project controlled by this department that has the maximum number of employees of the company working on it. The number of the above project. The cumulative sum of the number of employees of the company working on the projects...

  • Need help!! Java Eclipse Please provide the screenshot of output of code as well. thank you......

    Need help!! Java Eclipse Please provide the screenshot of output of code as well. thank you... PROGRAM 1 –Linear Data Structure Implementation (Due date: March 5th, 2019, 5% Grade Points) Given the starting point in a maze, you are to find and mark a path out of the maze which is represented by a 30x30 array of 1s (representing hedges) and 0s (representing the foot-paths). There is only one exit from the maze (represented by E). You may move vertically...

  • I need help with a project, I’ve seen many answers in C++, but i need it to be in swift, thank you!

    I need help with a project, I’ve seen many answers in C++, but i need it to be in swift, thank you! Write a program that asks the user to enter a date (e.g. July 4, 2008) and will return the day of the week that corresponds to that date. Your program should take the input in numeric form, thus the input prompt should be as follows: Please enter a date below: Enter month (1-12): Enter day (1-31) Enter year...

  • Hi good day i need homework help fast please d32 1./What is the maximum length that...

    Hi good day i need homework help fast please d32 1./What is the maximum length that a VARCHAR data type can be: a. 65535 b. 1023 C. 255 d. 32767 2.) Why are alias' used for table and columns? a. to make the names easier to understand b. to hide the column or table c. to be able to remove them from the database d. to give the appearance that they are new- 3.)What does the FIELD function allow you...

  • //Need help ASAP in c++ please. Appreciate it! Thank you!! //This is the current code I have. #include <iostream> #include <sstream> #include <iomanip> using namespace std; cl...

    //Need help ASAP in c++ please. Appreciate it! Thank you!! //This is the current code I have. #include <iostream> #include <sstream> #include <iomanip> using namespace std; class googlePlayApp { private: string name; double rating; int numInstalls; int numReviews; double price;    public: googlePlayApp(string, double, int, int, double); ~ googlePlayApp(); googlePlayApp();    string getName(); double getRating(); int getNumInstalls(); int getNumReviews(); string getPrice();    void setName(string); void setRating(double); void setNumInstalls(int); void setNumReviews(int); void setPrice(double); }; googlePlayApp::googlePlayApp(string n, double r, int ni, int nr, double pr)...

  • I need help on how to find the atmospheric pressure from the scatter plot and trend...

    I need help on how to find the atmospheric pressure from the scatter plot and trend line I made with the results from my Boyle's Law lab. I don't know if my scatter plot is correct. I need the atmospheric pressure in order to fill in Table 5 and answer some questions. 24. Use the data in Data Table 1 and Data Table 3 to create a scatter-plot graph of 1/Average Volume vs. Pressure; with “1/Average Volume (mL-1)” on the...

  • I need help writing this code in C++ Proj11.cpp is provided as well as the randomdata.txt thank you in advance! Objectives: The main objectives of this project is to introduce you to recursion,...

    I need help writing this code in C++ Proj11.cpp is provided as well as the randomdata.txt thank you in advance! Objectives: The main objectives of this project is to introduce you to recursion, and test your ability to work with some STL functionalities. A review of your knowledge on working with templates, dynamic data structures, as well as manipulating dynamic memory, classes, pointers and iostream to all extents, is also included. Description: For the entirety of this project, you will...

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