Basic SQL Queries: Find Max Customers & Products Handled

  • Thread starter WWGD
  • Start date
  • Tags
    Sql
In summary, the first query attempts to find which warehouse houses the most products, while the second query tries to find the customer who handles the most products.
  • #1
WWGD
Science Advisor
Gold Member
7,010
10,477
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
  • #2
How urgent is it and do you have some csv test data?
 
  • #3
  • #4
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.
 
  • #5
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
 
  • #7
Last edited:
  • Like
Likes WWGD

1. What is the purpose of using Basic SQL Queries to find the maximum customers and products handled?

Basic SQL Queries are used to retrieve specific data from a database. In this case, the query is used to find the maximum number of customers and products that have been handled, which can provide insight into the popularity and success of a business.

2. How do you structure a Basic SQL Query to find the maximum customers and products handled?

The query would start with the SELECT keyword, followed by the MAX function to find the maximum value. Then, specify the desired columns from the FROM clause and use the GROUP BY clause to group the data by the customer or product. The query would end with the ORDER BY clause to arrange the data in descending order and the LIMIT clause to limit the results to the highest value.

3. Can Basic SQL Queries be used to find the maximum customers and products handled over a specific time period?

Yes, the WHERE clause can be used to specify a date or time range to filter the data and only retrieve the maximum values within that period.

4. Are there any limitations to using Basic SQL Queries to find the maximum customers and products handled?

Basic SQL Queries are limited to querying data from a single database, so if the data is spread across multiple databases, the results may not be accurate. Additionally, the query may be affected by the data type and formatting of the columns being queried.

5. What are some potential applications of using Basic SQL Queries to find the maximum customers and products handled?

These types of queries can be useful for businesses to track their customer and product growth, identify popular products, and make data-driven decisions for future growth and marketing strategies. They can also be used for market research and competitor analysis.

Similar threads

  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
2
Replies
51
Views
4K
  • Set Theory, Logic, Probability, Statistics
2
Replies
67
Views
2K
  • Programming and Computer Science
Replies
7
Views
2K
  • Set Theory, Logic, Probability, Statistics
2
Replies
35
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
9
Views
802
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
Back
Top