Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MYSQL the title of the book published by this publisher that has the highest num

ID: 3700286 • Letter: M

Question

MYSQL the title of the book published by this publisher that has the highest number of onhand units collectively in all branches of henrybooks

I have these results from

SELECT SUM(OnHand) AS OnHand,BookCode,title FROM ((SELECT * FROM Book NATURAL JOIN Inventory WHERE publisherCode='JP') AS Book_Inventory) GROUP BY BookCode;

I want to select The title of the book published by this publisher that has the highest number
of onHand units collectively in all branches of Henry Books.

SELECT title FROM ((SELECT SUM(OnHand) AS OnHand,BookCode,title FROM ((SELECT * FROM Book NATURAL JOIN Inventory WHERE publisherCode='JP') AS Book_Inventory) GROUP BY BookCode)AS SUM_ONHAND) WHERE>

is what i'm trying but i get invalid use of group function

Author
authorNum
authorLast
Book
bookCode
title
publisherCode
Branch
branchNum
branchName
branchlocation
Inventory
Book
BranchNum
OnHand
Publisher
publisherCode
publisherName

OnHand bookCode title 0808 8720 9882 The Edge When Rabbit Howls Slay Ride 3 3

Explanation / Answer

Aggreagte functions like min,max,count,avg,sum we don't use int in directly in where clause...

In the given above problem you used "WHERE Here max is the aggregate function ...

Instead if where if you keep Having clause then there is no problem. In having we use Aggregate functions

or otherwise Instead of Having you should use Subquery also....

Method1 :

SELECT title FROM ((SELECT SUM(OnHand) AS OnHand,BookCode,title FROM ((SELECT * FROM Book NATURAL JOIN Inventory WHERE publisherCode='JP') AS Book_Inventory) GROUP BY BookCode)AS SUM_ONHAND) HAVING Max(OnHand).

Method2 :

SELECT title FROM ((SELECT SUM(OnHand) AS OnHand,BookCode,title FROM ((SELECT * FROM Book NATURAL JOIN Inventory WHERE publisherCode='JP') AS Book_Inventory) GROUP BY BookCode)AS SUM_ONHAND) WHERE OnHand in (SELECT Max(OnHand) FROM Inventory)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote