这个查询出现次数的SQL语句怎么写才好?

onlyonehaimeika 2003-09-01 06:47:16
对数据库
tid items
T100 I1,I2,I5
T200 I2,I4
T300 I2,I3
T400 I1,I2,I4
T500 I1,I3
T600 I2,I3
T700 I1,I3
T800 I1,I2,I3,I5
T900 I1,I2,I3
想要查询各项组合出现的次数,即以下结果的话,SQL语句应该怎么写才好。请各位发表高见
items count
I1,I2 4
I1,I3 3
I1,I4 1
I1,I5 2
I2,I3 4
I2,I5 2
I3,I5 1
...全文
113 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ckp 2003-09-11
  • 打赏
  • 举报
回复
gz
littlecpu 2003-09-10
  • 打赏
  • 举报
回复
不用在一棵树上吊死,求速用存储,不求速拉到开发工具中用高级语言统计
onlysgirl 2003-09-05
  • 打赏
  • 举报
回复
select count(1) from table group by items
onlyonehaimeika 2003-09-02
  • 打赏
  • 举报
回复
Thank you,webswim.I am trying to run it.
And thank you wawaren too.Yes ,It is a part of association rules mining.But I did not understand what you said very well.What does 'a,b'mean? Or what is in 'a,b'?Would you please say that more clearly?
I am very sorry to write in English.Because now,I can only read in Chanese but can not write.Really hope your helpness! Thank you.
wawaren 2003-09-02
  • 打赏
  • 举报
回复
这个就是查询所有长度为二的关联规则,可以通过该表的一个字连接来实现。

select a.itmes,b.items,count(*)
from a,b
webswim 2003-09-02
  • 打赏
  • 举报
回复
建立一张临时表tmp1(fld1),存储I1~I5, 用查询提取二维组合:
( select a.fld1 I_first, b.fld1 I_second
from tmp1 a, (select * from tmp1) b
where a.fld1 <> b.fld1
) x

然后判断上述二维组合在你的表(sourceData)中出现的次数:
select x.I_first + ',' + x.I_second as items, count(*) as count
from
( select a.fld1 I_first, b.fld1 I_second
from tmp1 a, (select * from tmp1) b
where a.fld1 <> b.fld1
) x, sourceData y
where b.items like '%' + x.I_first + '%'
and b.items like '%' + x.I_second + '%'
group by x.I_first, x.I_second

希望能有所帮助


onlyonehaimeika 2003-09-02
  • 打赏
  • 举报
回复
谢谢‘网中漫步’,在你的帮助下二维查询已经成功的运行了。

7,388

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 数据仓库
社区管理员
  • 数据仓库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧