我有一个费率表,可以按季度更改季度。
即
using System;
using System.Collections.Generic;
namespace Demo
{
class DupeInfo
{
public string Text;
public int Index;
public int Count;
}
static class Program
{
static void Main()
{
var test = new[]
{
"1",
"2", "2",
"A",
"3", "3", "3",
"B",
"4", "4", "4", "4",
"C",
};
foreach (var dupeinfo in FindRepeats(test))
Console.WriteLine($"{dupeinfo.Text} was repeated {dupeinfo.Count} times starting at index {dupeinfo.Index}");
}
public static IEnumerable<DupeInfo> FindRepeats(IEnumerable<string> input)
{
int i = 0;
int j = 0;
int c = -1;
string prev = null;
foreach (var curr in input)
{
if (curr != prev)
{
if (c >= 0)
yield return new DupeInfo {Text = prev, Count = c + 2, Index = j};
c = -1;
j = i;
}
else
{
++c;
}
prev = curr;
++i;
}
if (c >= 0)
yield return new DupeInfo {Text = prev, Count = c + 2, Index = j};
}
}
}
等。
我创建了一个Quarter字段:
+--------+-------+------+
| Q1 | | |
+--------+-------+------+
| Sales | | Rate |
| <1000 | | 1% |
| >=1001 | <2500 | 2% |
| >=2501 | | 3% |
+--------+-------+------+
| Q2 | | |
+--------+-------+------+
| Sales | | Rate |
| <1500 | | 1% |
| >=1501 | <3000 | 2% |
| >=3001 | | 3% |
+--------+-------+------+
尝试了所有类型的方法来制作等效方法:
Qtly Cum。销售
如果Quarter = 1则sum(Sales) elseif Quarter = 2 then sum(sales) 等...
所以我最终会以
结束if month([booking_date]) = 1 then 1
ELSEIF month([booking_date]) = 2 then 1
ELSEIF month([booking_date]) = 3 then 1
ELSEIF month([booking_date]) = 4 then 2
ELSEIF month([booking_date]) = 5 then 2
ELSEIF month([booking_date]) = 6 then 2
ELSEIF month([booking_date]) = 7 then 3
ELSEIF month([booking_date]) = 8 then 3
ELSEIF month([booking_date]) = 9 then 3
ELSEIF month([booking_date]) = 10 then 4
ELSEIF month([booking_date]) = 11 then 4
ELSEIF month([booking_date]) = 12 then 4
END