Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6868913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:29:33+00:00 2026-05-27T03:29:33+00:00

I’ve not had any luck searching for a solution to this, partly because I’m

  • 0

I’ve not had any luck searching for a solution to this, partly because I’m not exactly sure how best to explain the problem! Hopefully I’m clear here but if not please feel free to ask for more info.

At the top level:
In our database, each customer can have multiple services. Services are allocated to a customer individually. However, we need ‘group’ services into ‘packages’ of common service combinations for reporting purposes.

I have a database which contains package definitions – a table called packageServices, simply listing each PackageID with an associated ServiceID. Therefore I can retrieve a list of services for each package.

From the same database I can retrieve a list of ServiceIDs for a particular customer.

What I am trying to accomplish is to compare the list of ServiceIDs retrieved for that customer, and see if that combination matches any of the defined pacakges (i.e. combinations of ServiceIDs) and if so report which package(s) that customer has.

I’m struggling to know where to begin so far as the comparison goes! I guess I need to start by creating some sort of list of serviceIDs for each package (rather than my current KeyValuePairs (in the dictionary) with multiple lines for each package?) then iterate through the packages and compare those lists of services with the list of services that customer has?

The data types used here may not be most appropriate – in many cases I’m referring to a ‘logical’ list rather than a C# List object – I can use whichever datatype is appropriate 🙂

Any help much appreciated!

EDIT – It’s been suggested that I collate this information in SQL instead of in my C# application. This seems like a good idea and one of the answers below has brought me close. However, there are ‘business rules’ in place which determine whether a package is an ‘upgrade’ of a lower package or a package in itself and this is seriously complicating things.

The more I try to make this work the more I think that I’ve bitten off more than I can chew! I am trying to design this properly, so that any changes to services or packages in the future will be handled easily – these changes are unlikely but possible. However, it would be much easier to just to hardcode the options from what I’ve seen so far!

EDIT 2 – I’ve been working through this and it has been suggested that I assign a ‘weight’ and a ‘group’ to each package. The groups are there to ensure that a customer can only have one package from each group, and the weights are there to ensure that only the ‘highest’ level package is returned. Using this in conjunction with @MarceloCantos ‘s query will mean that I should be able to return just the ‘highest’ weight package from each group – this looks like it might fit the requirements of the application!

Thanks to all who have helped so far – I’m amazed how quickly the responses started coming in and at the quality of the responses given. I’ll give this a go and see how I get on.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:29:33+00:00Added an answer on May 27, 2026 at 3:29 am

    You can count the services for the customer and then, for each package that has the same number of services, count the services that match the customer’s services. Only an exact match will yield the same count.

    You can do this in a single query, albeit a rather tricksy one:

    SELECT CustomerID, PackageID
      FROM (SELECT CustomerID, COUNT(*) AS qty
              FROM customerServices
             GROUP BY CustomerID
           ) cs
      JOIN (SELECT PackageID, COUNT(*) AS qty
              FROM packageServices
             GROUP BY PackageID
           ) ps ON cs.qty = ps.qty
     WHERE (SELECT COUNT(*)
              FROM customerServices cs2
              JOIN packageServices ps2 ON cs2.ServiceID = ps2.ServiceID
             WHERE cs2.CustomerID = cs.CustomerID
               AND ps2.PackageID = ps.PackageID
           ) = ps.qty
    

    EDIT: Perhaps I misunderstood the question. If you want to find packages that contain a subset of the customer’s services, you can do this instead:

     ...
           ) ps ON cs.qty >= ps.qty -- Change the test
     WHERE (SELECT COUNT(*)
              FROM customerServices cs2
              JOIN packageServices ps2 ON cs2.ServiceID = ps2.ServiceID
             WHERE cs2.CustomerID = cs.CustomerID
               AND ps2.PackageID = ps.PackageID
           ) = ps.qty
    

    EDIT 2: I changed the logic of the second case to exploit the fact that if the intersection of two sets is the same size as the smaller set, then the smaller set is a subset of the larger.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need a function that will clean a strings' special characters. I do NOT
Does anyone know how can I replace this 2 symbol below from the string
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.