我有个问题。考虑 ROLAP 系统中的以下事实和维度表,该系统收集在超市销售的食品中测量的有害物质的值。
事实表:
• Contaminants (TimeID, ShopID, FoodID, substance, quantityPerOunce)
This describes which harmful substance in which quantity was found on a given
food in a given supermarket at a given time.
维度表:
• Time (TimeID, dayNr, dayName, weekNr, monthNr, year)
• Food (FoodID, foodName, brand, foodType)
Example data: (43, egg, Bioland, animalProduct)
• Place (ShopID, name, street1, region, country)
编写一条 SQL 语句来创建一个回答以下查询的报告:
- 列出在德国萨克森、图林根和黑森地区每年测量的动物产品和蔬菜(均为 foodTypes)中物质“PCB”的最低含量。
- 结果应包含年份、地区和最小值。
用同样的说法,也列出
- 每年的最小值(即每年汇总所有区域)
- 以及上述地区所有年份和所有地区的动物产品和蔬菜中 PCB 最低数量的总和。
SQL查询
SELECT years, regions, min(quantityPerOunce)
FROM Contaminants as c, Time as t, Food as f, Place as p
WHERE c.TimeID = t.TimeID
AND c.FoodID = f.FoodID
AND c.ShopdID = p.ShopID
AND substance = "PCB"
AND foodType = "vegetables"
AND foodType = "animalProducts"
GROUP BY regions;
我不知道如何解决这种练习。我试过了,但我不知道。即使这不是最好的方式,也应该 加入。Equi-Join