Basic SQL Queries: Find Max Customers & Products Handled

  • Thread starter Thread starter WWGD
  • Start date Start date
  • Tags Tags
    Sql
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
6 replies · 2K views
Messages
7,822
Reaction score
13,151
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   Reactions: Silicon Waffle
Physics news on Phys.org
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
 
Last edited:
  • Like
Likes   Reactions: WWGD