這篇文章是關於在數據庫中存放的一張簡單表來依照 未經優化的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 product
group 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 l2
where 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 , C2
where p1.pname like C2.cpname1 and
p2.pname like C2.cpname2
group by C2.cpname1,C2.cpname2
having count(*) >= 3;
---------------------
select * from C22 ;