Basic SQL Queries: Find Max Customers & Products Handled

  • Thread starter Thread starter WWGD
  • Start date Start date
  • Tags Tags
    Sql
Click For Summary

Discussion Overview

The discussion revolves around constructing SQL queries to determine which sales representative handles the most customers and which warehouse houses the most products. It includes aspects of query formulation and troubleshooting SQL syntax.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant presents a query to find the sales rep with the most customers, expressing uncertainty about its correctness.
  • Another participant proposes a query to identify the warehouse with the most products, also questioning its validity.
  • Some participants inquire about the urgency of the queries and the availability of test data in CSV format.
  • A participant shares their experience with SQL, mentioning a preference for a trial-and-error approach to fix errors in SQL statements.
  • Another participant suggests using the H2 database engine as a potential solution for database issues, providing links to resources.

Areas of Agreement / Disagreement

Participants express varying levels of confidence in the SQL queries presented, with no consensus on their correctness. There is also a lack of agreement on the urgency of the task and the availability of test data.

Contextual Notes

Some participants mention difficulties with accessing previous work and data, which may affect their ability to test the SQL queries. There is also an indication that the queries may be more complex than necessary, but this remains unverified.

WWGD
Science Advisor
Homework Helper
Messages
7,802
Reaction score
13,106
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
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
 
Last edited:
  • Like
Likes   Reactions: WWGD

Similar threads

  • · Replies 51 ·
2
Replies
51
Views
6K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 67 ·
3
Replies
67
Views
4K
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 35 ·
2
Replies
35
Views
3K
Replies
5
Views
2K
  • · Replies 9 ·
Replies
9
Views
1K
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K