-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Data Analysis Using SQL and Excel - Second Edition
By :
The calculation for two-way association rules follows the same logic as for the one-way rules. This section looks at the SQL for generating such rules, as well as some interesting extensions by extending the idea of item and the relationships among them.
The basic query for calculating two-way associations is quite similar to the query for one-way associations. The difference is that the left-hand side has two products rather than one.
The following two rules are equivalent:
Hence, the products on the left-hand side are an item set, so the products should not be repeated.
This query implements this by requiring that the first product ID be smaller than the second on the left-hand side. The left- and right-hand sides of the rule are different, so each needs its own CTE:
WITH items as (
SELECT ol.OrderId as basket, p.ProductId as item,
COUNT(*) OVER (PARTITION BY p.ProductId) as...
Change the font size
Change margin width
Change background colour