azwaan
Programmer
- Jan 11, 2002
- 42
i have a transaction table that which looks somewhat like this, only a lot more data
TranID ITEM
1 soap
1 coke
1 bag
2 coke
2 apple
3 soap
2 apple
i have the following statement to show association rules
SELECT b1.item, b2.item AS item2, count(*) as support
FROM transactions AS b1, transactions AS b2
WHERE b1.tranid=b2.tranid and b1.item < >b2.item
GROUP BY b1.item, b2.item
HAVING count(*) > = 3
ORDER by b1.item, b2.item
OPTION (hash group)
the results i get is somwhat like this,
Item Item2 Support
row1 apple coke 2
row2 coke apple 2
row3 coke soap 3
row4 soap coke 3
as shown, there rows 1 & 2 contain the same data. as does rows 3 & 4.
can someone suggest how i can modify the statement to avoid duplicates ? or an alternative way of doing this?
TranID ITEM
1 soap
1 coke
1 bag
2 coke
2 apple
3 soap
2 apple
i have the following statement to show association rules
SELECT b1.item, b2.item AS item2, count(*) as support
FROM transactions AS b1, transactions AS b2
WHERE b1.tranid=b2.tranid and b1.item < >b2.item
GROUP BY b1.item, b2.item
HAVING count(*) > = 3
ORDER by b1.item, b2.item
OPTION (hash group)
the results i get is somwhat like this,
Item Item2 Support
row1 apple coke 2
row2 coke apple 2
row3 coke soap 3
row4 soap coke 3
as shown, there rows 1 & 2 contain the same data. as does rows 3 & 4.
can someone suggest how i can modify the statement to avoid duplicates ? or an alternative way of doing this?