[sql] 使用sql语句实现 Aprior 频繁二项集搜索

来源:互联网 发布:怎么安装虚拟机linux 编辑:程序博客网 时间:2024/05/17 09:10

这篇文章是关于在数据库中存放的一张简单表来依照 未经优化的Aprior 算法,

搜索频繁二项集的实验。  使用的SQL语句均通过验证,可以直接使用。


database : mysql

schema name : test

table name :

product

----------------------

pid | pname

----------------------

1 I1

2 I2

3 I3

4 I5

5 I2

6 I4

7 I1

8 I2

9 I3

10 I5

--------------------


首先,从数据库表 producer 生成一项集

SQL : select L1

use test ; drop table L1 ;-----------------------create table if not exists L1 ( id int not null AUTO_INCREMENT ,pname varchar(50) ,  count int ,primary key(id)) ;------------------------insert into  L1   (pname ,count)select  pname , count(*)  from productgroup by (pname)having count(*) >= 2;-----------------------select * from L1 ;




SQL : select_C2

use test ;drop table C2 ;-----------------------create table C2 (id int auto_increment,cpname1 varchar (50) ,cpname2 varchar(50) ,primary key(id)) ;-----------------------insert into C2( cpname1,cpname2)select l1.pname , l2.pname  from L1 l1 , L1 l2where  l1.id < l2.id ;----------------------select * from C2 ;



SQL : select_C22:

use test ;drop table C22 ;-----------------------create table C22(id int auto_increment,ccpname1 varchar(50) ,ccpname2 varchar(50) ,count int ,primary key (id)) ;-----------------------insert into  C22(ccpname1, ccpname2,count)select p1.pname ,p2.pname  ,count(*)from product p1 ,product p2 , C2where p1.pname like C2.cpname1 and p2.pname like C2.cpname2 group by  C2.cpname1,C2.cpname2having count(*) >= 3;---------------------select * from C22 ;



 


0 0
原创粉丝点击