【发布时间】:2014-05-05 08:27:54
【问题描述】:
考虑以下查询,该查询生成 customerid 和他们购买特定产品的日期,显然每个客户都有不同的购买日期。我想做的是在客户购买该产品的那几天获得总购买量。
我有 ff 查询。
Select customerid, eventdate
into #days
from table1
where product='chocolate'
现在我想总结客户购买“巧克力”的那几天的所有购买。 所以我有
select customerid, sum(purchases) purchases
into #pur
from table1 a
where eventdate in (select eventdate from #days where customerid=a.customerid)
group by customerid
但是上面的运行需要很长时间,所以我取消了它。 请协助更好的查询。
【问题讨论】:
标签: sql sql-server