Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get All Combinations
Message
 
 
À
19/01/2016 14:31:15
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
01629948
Message ID:
01629950
Vues:
47
Problem 1 is simple

select A.Value, B.Value from myTable A inner join myTable B on A.Value < B.Value

The other problems should have similar solutions - it is a cross join of your table multiple times. There should be not too many rows in the table.

>I have a table with 5 values
>A1
>B2
>C3
>D4
>E5
>
>Problem 1
>I need to be able to get all possible 2 value combinations of these values
>A1,B2
>A1,C3
>A1,D4
>A1,E5
>B2,C3
>B2,D3
>B2,E4
>C3,D4
>C3,E5
>D4,E5
>
>Problem 2
>I need to be able to get all possible 3 value combinations
>A1,B2,C3
>A1,B2,D4
>A1,B2,E5
>A1,C3,D4
>A1,C3,E5
>A1,D4,E5
>B1,C3,D4
>B2,C3,E5
>B2,D4,E5
>C3,D4,E5
>
>Real Problem
>A function/procedure/etc that can get all possible combination of length 2 through N
>
>MYPROC @table, 3 -- all results for combinatins of 2 or 3
>A1,B2
>A1,C3
>A1,D4
>A1,E5
>B2,C3
>B2,D3
>B2,E4
>C3,D4
>C3,E5
>D4,E5
>A1,B2,C3
>A1,B2,D4
>A1,B2,E5
>A1,C3,D4
>A1,C3,E5
>A1,D4,E5
>B1,C3,D4
>B2,C3,E5
>B2,D4,E5
>C3,D4,E5
>
>I've done something like this in VFP but I don't think my solution is transportable.
>
>Google didn't show (or at least I didn't find) any examples of what I need and I am unable to figure out how to modify what came close.
>
>If somebody has done something like this I can really use some guidance.
>
>Thanks.....................Rich
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform