Basic SQL Queries: Find Max Customers & Products Handled

  • Thread starter Thread starter WWGD
  • Start date Start date
  • Tags Tags
    Sql
AI Thread Summary
The discussion centers around two SQL queries aimed at identifying key data points from customer and warehouse tables. The first query seeks to determine which sales representative manages the most customers by counting the entries in the Customer table, using a nested query to find the maximum count. The second query aims to identify the warehouse with the highest number of products on hand by summing the OnHand values in the Part table and comparing it to the maximum sum from a nested query. Participants express concerns about the complexity of the queries and the inability to test them due to technical issues. Suggestions for resolving these issues include using alternative text editors to access data and recommending the H2 database engine for testing SQL statements. The urgency of resolving these queries is also highlighted, as it affects the user's ability to complete their work.
WWGD
Science Advisor
Homework Helper
Messages
7,678
Reaction score
12,344
Hi all,
I am reviewing some material and I have been stuck on these (I am a slow starter, I guess)

1) I have the table Customer, which has an entry on sales reps for customers. I want to know which sales
rep handles the most customers. Here is what is given

Customer ( CustNum PK, CustName, RepNum,...)

Where RepNum is the sales rep that handles a given customer.

My attempt is : select repnum from customer, group by repnum having Count(RepNum) =
(select max(count(repnum)) from customer, group by repnum)

Does this work?

-------------------------------------------------------

2) I want to know which warehouse houses the most products (given by OnHand below), using the table part:

Part(PartNum, warehouse, OnHand ,... )

My attempt: select warehouse from part group by warehouse having sum(OnHand) = (select

max(sum(onHand)) from part, group by warehouse ).

Does that work?

Thanks. Sorry, My SQL is not running, so I cannot test the queries myself.
 
  • Like
Likes Silicon Waffle
Technology news on Phys.org
How urgent is it and do you have some csv test data?
 
comma separated values
My experiences date back a while but I have a DB server running. To me your queries look a bit complicated, however, I do not dare to judge them. Normally I use the try and error method to fix my errors in sql statements. Guess I could try the second one right away but I have no good data on customer reps. My question on how urgent it is, is due to the fact that my sleep is (again) overdue.o
Edit: try an hex editor to open it, or 'textpad'. The latter opens everything and should be available as demo version.
 
fresh_42 said:
comma separated values
My experiences date back a while but I have a DB server running. To me your queries look a bit complicated, however, I do not dare to judge them. Normally I use the try and error method to fix my errors in sql statements. Guess I could try the second one right away but I have no good data on customer reps. My question on how urgent it is, is due to the fact that my sleep is (again) overdue.
Thank you, I can send you the schema as an attachment
 
Back
Top