troubleshooting Question

Grouping information based on highest repeats

Avatar of restockit
restockit asked on
Microsoft SQL ServerMicrosoft SQL Server 2005
7 Comments2 Solutions252 ViewsLast Modified:
table1 contains a list of all the skus that a customer has purchased from us throughout the lifetime of them ordering. Each sku is associated to 1 of 5 different categories.
I need a query that will select the 1 category that appears the most per customer ID. Please help.

Note: total # of unique skus is irrelevant.
Also, the category must be chosen based on the categories located in all orders placed by customer.
See sample of data below including intended result

intended result:
custID   Category
10          Kitchen (was in 4 different rows)
11          Kitchen (was in 3 different rows)

DATA:

pk      custID      OrderNum      SKU      Category
1      10      1      JET123      Kitchen
2      10      1      CD3      Office
3      10      1      ABU7834      Kitchen
4      10      2      JET123      Kitchen
5      10      2      RBT134      Janitorial
6      10      2      JET123      Kitchen
7      10      3      CD3      Office
8      11      4      ET12      Kitchen
9      11      4      D3      Office
10      11      4      AU834      Kitchen
11      11      5      JE13      Kitchen
12      11      5      RT34      Janitorial
13      11      5      eT12      Disposables
14      11      6      CD      Office
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros