我有一份订单清单,以及每个订单中销售的商品清单。
但是,我只想计算物品出售的第一个月内售出的物品。通常可以通过查看项目出现的最短日期来计算出来。
以下是一些示例代码
DECLARE @sales table(
itemnumber int,
saledate date,
ordid int)
INSERT INTO @sales VALUES(43029, '2011-26-03', 1)
INSERT INTO @sales VALUES(43029, '2011-26-03', 2)
INSERT INTO @sales VALUES(43029, '2011-26-03', 3)
INSERT INTO @sales VALUES(43029, '2011-26-03', 4)
INSERT INTO @sales VALUES(43029, '2011-26-03', 4)
INSERT INTO @sales VALUES(43029, '2011-26-04', 4)
INSERT INTO @sales VALUES(43029, '2011-26-04', 5)
INSERT INTO @sales VALUES(43029, '2011-26-04', 5)
INSERT INTO @sales VALUES(43030, '2011-26-04', 5)
INSERT INTO @sales VALUES(43030, '2011-26-04', 6)
INSERT INTO @sales VALUES(43030, '2011-26-04', 7)
INSERT INTO @sales VALUES(43030, '2011-26-04', 8)
INSERT INTO @sales VALUES(43030, '2011-26-04', 8)
INSERT INTO @sales VALUES(43030, '2011-26-04', 8)
INSERT INTO @sales VALUES(43030, '2011-26-05', 9)
INSERT INTO @sales VALUES(43030, '2011-26-05', 9)
INSERT INTO @sales VALUES(43030, '2011-26-05', 9)
INSERT INTO @sales VALUES(43030, '2011-26-05', 9)
INSERT INTO @sales VALUES(43030, '2011-26-05', 9)
INSERT INTO @sales VALUES(43030, '2011-26-05', 9)
INSERT INTO @sales VALUES(43030, '2011-26-05', 19)
INSERT INTO @sales VALUES(43030, '2011-26-05', 19)
INSERT INTO @sales VALUES(43030, '2011-26-05', 25)
INSERT INTO @sales VALUES(43030, '2011-26-05', 25)
INSERT INTO @sales VALUES(43030, '2011-26-05', 25)
INSERT INTO @sales VALUES(43030, '2011-26-05', 27)
INSERT INTO @sales VALUES(43030, '2011-26-05', 27)
INSERT INTO @sales VALUES(43030, '2011-26-05', 27)
INSERT INTO @sales VALUES(43050, '2011-26-05', 28)
INSERT INTO @sales VALUES(43050, '2011-26-05', 29)
INSERT INTO @sales VALUES(43050, '2011-26-05', 39)
INSERT INTO @sales VALUES(43050, '2011-26-05', 30)
INSERT INTO @sales VALUES(43050, '2011-26-06', 31)
INSERT INTO @sales VALUES(43050, '2011-26-06', 31)
INSERT INTO @sales VALUES(43090, '2011-26-07', 61)
INSERT INTO @sales VALUES(43090, '2011-26-07', 61)
INSERT INTO @sales VALUES(43090, '2011-26-07', 61)
INSERT INTO @sales VALUES(43090, '2011-26-07', 61)
INSERT INTO @sales VALUES(43090, '2011-26-08', 71)
INSERT INTO @sales VALUES(43090, '2011-26-08', 71)
输出结果如下表所示,仅计算该项目的第一个月销售额的订单
ItemNo | MonthYear | Count
-------------------------
43029 | 03-2011 | 5
43030 | 04-2011 | 6
43050 | 05-2011 | 4
43090 | 07-2011 | 4
我能够通过ITEM NO获得总计数以及显示第一个ord日期,并计算当天销售的商品数量,但无法计算所有月份/年份的项目汇总,因为该项目可能在同月的多个订单/日期出售
任何帮助都会很棒!
答案 0 :(得分:1)
试试这个
If tbxSubmit.Text.Equals(GetCell(x, 0)) Then
结果
Function RemoveWhitespace(fullString As String) As String
Return New String(fullString.Where(Function(x) Not Char.IsWhiteSpace(x)).ToArray())
End Function
答案 1 :(得分:0)
使用Jonathan Willcock的样本数据..
由于您在2012年,您可以使用窗口功能,如下所示..
{{1}}