我有一个表,收集订单.领域是:
> customerName(text)
> DateOfOrder(datetime).
我想每个客户每周显示订单总额.我想安排每周的星期五,这样看起来像这样:
all dates follow mm/dd/yyyy "bobs pizza",3/5/2010,10 "the phone co",5 "bobs pizza",3/12/2010,3 "the phone co",11
有人可以告诉我怎么做吗?
谢谢
解决方法
做一个你可以更容易地分组的领域.
SELECT COUNT(OrderID),WeekStart FROM ( SELECT *,dateadd(week,datediff(day,'20000107',yourDate) / 7,'20000107') AS WeekStart FROM Orders ) o GROUP BY WeekStart;
20000107是一个知名的星期五.