我的表(products
)是如下:计算过去7天,每天在范围
id, productId, price, saleDate
我想建立一个查询,具体productId
和具体的数据范围将返回价格的平均水平该范围内每天的最后7天。
以下查询会给我所有的数据,具体的productId 16年1月1日和16年2月1日之间
SELECT * FROM products WHERE productId='PS54434' AND saleDate BETWEEN '2016-01-01' AND '2016-02-01'
,但我想,对于每16年1月1日一天,直到02/01/16我将收到最后7天 所以对于数据01/01/16我将收到12/26/16-01/01/16价格的平均值
什么版本的SQL Server? – RBarryYoung