我在一个看起来像这样的表中有数据:
VISIT ID | Surgeon | Surgeon Arrival Before Schedule in Minutes | ...
123 | Dr. A | -45
156 | Dr. A | -25
198 | Dr. A | 32
... | ...
我想构建一个将 bin 和 count 的查询,这意味着我想要如下输出:
Surgeon | Bin 1 | Bin 2 | Bin 3 | ... | Bin 6
Dr. A | 2 | 0 | 4 | ... | 0
上面,Bin(s) 定义了Surgeon Arrival Before Schedule in Minutes
列落入具有以下逻辑的 bin 的位置:
Bin 1 = Surgeon Arrival Before Schedule in Minutes <= -30
Bin 2 = -30 < Surgeon Arrival Before Schedule in Minutes <= -15
Bin 3 = -15 < Surgeon Arrival Before Schedule in Minutes <= 0
Bin 4 = 0 < Surgeon Arrival Before Schedule in Minutes <= 15
Bin 5 = 15 < Surgeon Arrival Before Schedule in Minutes <= 30
Bin 6 = Surgeon Arrival Before Schedule in Minutes > 30
我想有COUNT
多少Encounter ID
数字落入每个箱中以产生所需的结果。
我一直在尝试查询,例如:
TRANSFORM Count([or on time log].[ENCOUNTER ID]) AS CountOfID
SELECT [or on time log].[Surgeon]
FROM [or on time log]
GROUP BY [or on time log].[Surgeon]
PIVOT IIf([Surgeon Arrival Before Schedule in Minutes] <= -30, "Bin 1",
IIf(-30 < [Surgeon Arrival Before Schedule in Minutes] <= -15, "Bin 2",
IIf(-15 < [Surgeon Arrival Before Schedule in Minutes] <=0, "Bin 3",
IIf(0 < [Surgeon Arrival Before Schedule in Minutes] <=15, "Bin 4",
IIf(15 < [Surgeon Arrival Before Schedule in Minutes] <= 30, "Bin 5",
IIf(30 < [Surgeon Arrival Before Schedule in Minutes], "Bin 6")
)
)
)
)
)
;
这样做只给了我不准确的 bin 1 和 3 Surgeon。