製品グループ
ProductGroupID Description
301 Shampoo
302 Soap
303 Brush
製品
ProductID ProductGroupID Desc Price
4001 301 Shampoo1 2
4002 301 Shampoo2 3
4003 301 Shampoo3 4
4004 302 Soap1 2
4005 302 Soap2 3
4006 302 Soap3 5
4007 303 Brush1 6
4008 303 Brush2 7
4009 303 Brush3 8
注文
OrderID ProductID
50001 4001
50002 4002
50003 4002
50004 4002
50005 4003
50006 4007
50007 4009
50008 4003
50009 4001
50010 4005
50011 4008
50012 4009
フィルタリングなし
Select p.ProductID, p.Desc, pg.ProductGroupID, pg.Description Count(o.ProductID) as OrderNum, p.Price
From Order o
inner join Product p
ON o.ProductID = p.ProductID
inner join ProductGroup pg
ON p.ProductGroupID = pg.ProductGroupID
Group By p.ProductID, p.Desc, pg.ProductGroupID, pg.Description, p.Price with Cube
Having ProductGroupID is not null
ProductID Desc ProductGroupID Description OrderNum Price
4001 Shampoo1 301 Shampoo 2 2
4002 Shampoo2 301 Shampoo 3 3
4003 Shampoo3 301 Shampoo 2 4
-------- -------- 301 Shampoo 7 ----
4004 Soap1 302 Soap 0 2
4005 Soap2 302 Soap 1 3
4006 Soap3 302 Soap 0 5
-------- -------- 302 Brush 1 ----
4007 Brush1 303 Brush 1 6
4008 Brush2 303 Brush 1 7
4009 Brush3 303 Brush 2 8
-------- -------- 303 Brush 4 ----
小計でフィルタリングあり
Select p.ProductID, p.Desc, pg.ProductGroupID, pg.Description Count(o.ProductID) as OrderNum, p.Price
From Order o
inner join Product p
ON o.ProductID = p.ProductID
inner join ProductGroup pg
ON p.ProductGroupID = pg.ProductGroupID
Group By p.ProductID, p.Desc, pg.ProductGroupID, pg.Description, p.Price with Cube
Having ProductGroupID is not null
AND SubTotal(OrderNum) => 4 -- not working
ProductID Desc ProductGroupID Description OrderNum Price
4001 Shampoo1 301 Shampoo 2 2
4002 Shampoo2 301 Shampoo 3 3
4003 Shampoo3 301 Shampoo 2 4
-------- -------- 301 Shampoo 7 ----
4007 Brush1 303 Brush 1 6
4008 Brush2 303 Brush 1 7
4009 Brush3 303 Brush 2 8
-------- -------- 303 Brush 4 ----
小計でどのようにフィルタリングしますか?