我有查询返回有关整体销售的结果,但现在我想通过添加DATE
间隔来过滤它们。
编辑:fs.DateKey
是DateTime
数据类型
我原来的查询:
SELECT s.storekey,
e.employeekey,
e.parentemployeekey,
pc.productcategorykey,
pc.productcategoryname,
Sum(fs.salesamount)AS SalesAmount
FROM dimstore s
INNER JOIN factsales fs
ON fs.storekey = s.storekey
RIGHT JOIN dimemployee e
ON e.employeekey = s.storemanager
INNER JOIN dimproduct p
ON p.productkey = fs.productkey
INNER JOIN dimproductsubcategory psc
ON psc.productsubcategorykey = p.productsubcategorykey
INNER JOIN dimproductcategory pc
ON pc.productcategorykey = psc.productcategorykey
GROUP BY s.storekey,
e.employeekey,
e.parentemployeekey,
pc.productcategoryname,
pc.productcategorykey
ORDER BY employeekey
我正在考虑添加WHERE fs.DateKey BETWEEN '2007-01-20' AND '2007-01-25'
,但由于某种原因结果不正确。我不明白为什么。有什么提示或建议可以达到预期的效果吗?
谢谢!