在 TSQL 中生成组合最有效、最灵活的方法是什么?
在 TSQL 中生成组合最有效、最灵活的方法是什么? 对于“灵活”,我的意思是您应该能够轻松添加组合规则。例如:生成“n”个元素的组合、排序、删除重复项、获取每个奖品属于不同彩票的组合等。
例如,拥有一组代表彩票奖品的数字。
Number | Position | Lottery
---------------------------
12 | 01 | 67
12 | 02 | 67
34 | 03 | 67
43 | 01 | 89
72 | 02 | 89
33 | 03 | 89
(我包含位置列,因为不同彩票的奖品之间可能会重复一个数字)
我想生成如下组合:
Numbers | Lotteries
-------------------
12 12 | 67 67
12 34 | 67 67
12 34 | 67 67
12 43 | 67 89
12 72 | 67 89
12 33 | 67 89
.
.
.
What is the most effective and flexible way to generate combinations in TSQL?
With 'Flexible', I mean you should be able to add easily combination rules. e.g.: to generate combinatories of 'n' elements, sorting, remove duplicates, get combinatories where each prize belongs to a different lottery, etc.
For example, Having a set of numbers representing lottery prizes.
Number | Position | Lottery
---------------------------
12 | 01 | 67
12 | 02 | 67
34 | 03 | 67
43 | 01 | 89
72 | 02 | 89
33 | 03 | 89
(I include the position column because, a number could be repeated among different lottery's prizes)
I would like to generate combinatories like:
Numbers | Lotteries
-------------------
12 12 | 67 67
12 34 | 67 67
12 34 | 67 67
12 43 | 67 89
12 72 | 67 89
12 33 | 67 89
.
.
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这称为交叉连接:
This is called a CROSS JOIN:
更复杂的方法是使用 F#,以便用户可以使用领域特定语言编写方程。
有关如何使用 F# 的示例,您可以查看此博客中的最终评论:
http: //cs.hubfs.net/forums/thread/4496.aspx
原因是因为您需要想出一种由用户编写的简单方法来进行计算,但是,另一种选择是使用 C# 和实体属性值结构 (http://en.wikipedia.org /wiki/Entity-attribute-value_model),这样您就可以拥有一个灵活的系统,用户可以在其中为不同类型的彩票或不同的规则创建方程式。
但所有这些对于您的需求来说可能有点过大,具体取决于您真正需要多少灵活性。
The more complicated approach would be to use F# so that the user can write equations using a Domain Specific Language.
For an example of how to use F# you can see the final comment in this blog:
http://cs.hubfs.net/forums/thread/4496.aspx
The reason being because you will need to come up with an easy way to do the calculations, written by the user, but, the other option is to use C# and an Entity-Attribute-Value structure (http://en.wikipedia.org/wiki/Entity-attribute-value_model), so that you can have a flexible system where the user can create equations for different types of lotteries, or differing rules.
But all of these may be more overkill for what you need, depending on how much flexibility you really need.