从SQL中选择项目集 [英] Select itemset from SQL

查看:59
本文介绍了从SQL中选择项目集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,



我不是最强大的SQL开发人员,我只是快速询问是否有可能。



我有下表:



项目集

itemsetid productid

| 1 | 5 |

| 1 | 6 |

| 2 | 5 |

| 2 | 9 |



我想做的是返回所有项目集并知道有多少项目集。



我要归还的内容:

[[1(5,6)],[2(5,9)]] - > ;这长度= 2(项目集数量)



这些内容。



任何帮助都是非常感谢,



谢谢

Hey guys,

I am not the strongest SQL developer, I just have a quick question checking if this is possible.

I have the following table:

Itemsets
itemsetid productid
| 1 | 5 |
| 1 | 6 |
| 2 | 5 |
| 2 | 9 |

What I want to do is return all the itemsets and know how many are there.

What I want returned:
[[1(5,6)],[2(5,9)]] -> length of this = 2(number of itemsets)

Something along these lines.

Any help is greatly appreciated,

Thanks

推荐答案

select itemsetid, count(1) from  itemsets group by itemsetid



这会给你



1 2

2 2


this will give you

1 2
2 2


这是一项特殊要求,我建议你为此制作代码。

您有3种可能性( http: //www.codeguru.com/cpp/data/mfc_database/misc/article.php/c12615/MySQL-UDFs.htm [ ^ ]):

- 存储过程 [ ^ ]

- UDF

- 本机功能



这取决于您的编程知识以及您对服务器的访问权限。如果您需要快速处理并且可以使用C编写它并将UDF部署到服务器,请执行此操作。如果没有,请编写存储过程。
This is a special requirement, I suggest you make code for that.
You have 3 possibilities (http://www.codeguru.com/cpp/data/mfc_database/misc/article.php/c12615/MySQL-UDFs.htm[^]):
- Stored procedure[^]
- UDF
- Native function

It depends on your programming knowledge and the access you have to the server. If you need fast processing and you can write it in C and deploy the UDF to the server, do it. If not, write a stored procedure.


这篇关于从SQL中选择项目集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆