我一直在使用以下
from . import RecurrenceRelationParser
ImportError: cannot import name 'RecurrenceRelationParser'
计算在DATEDIFF(dd,OrderReceivedDate, DeliveryDate) DaysToDelivery
和OrderReceivedDate
之间花费的天数
我希望计算每个部门的第90个百分位数。
我有以下
DeliveryDate
我无法使它正常工作
当尝试使用PERCENTILE_DISC(0.9)
WITHIN GROUP (ORDER BY DATEDIFF(dd,OrderReceivedDate, DeliveryDate))
OVER (PARTITION BY Department) as 90thpercentile
时不允许日期区分吗?还是必须使用存储的图形?
我一直收到错误-OrderReceivedDate或DeliveryDate不在聚合或group by子句中
请帮助
答案 0 :(得分:1)
datediff
支持PERCENTILE_DISC,我已经在2016 sql server中测试了您的查询,效果很好
SELECT PERCENTILE_DISC(0.9)
WITHIN GROUP (ORDER BY DATEDIFF(dd,OrderReceivedDate, DeliveryDate))
OVER (PARTITION BY Department) as "90thpercentile"
from t
我认为列别名中存在问题,请使用双引号或[]作为 数字以列名开头
答案 1 :(得分:0)
示例代码..您期望的结果集是什么?
--drop table #Temp_Orders
create table #Temp_Orders
(
OrderNo int null
,Department varchar(30) null
,OrderReceivedDate date null
,DeliveryDate date null
)
insert into #Temp_Orders values
(1,'Acc','12-1-2018','12-2-2018')
,(1,'Acc','12-5-2018','12-8-2018')
,(1,'Warehouse','12-1-2018','12-12-2018')
,(1,'Warehouse','12-10-2018','12-12-2018')
,(1,'Acc','11-1-2018','11-29-2018')
,(1,'Acc','10-1-2018','10-9-2018')
select *
,PERCENTILE_DISC(0.9) WITHIN GROUP (ORDER BY DATEDIFF(dd,OrderReceivedDate, DeliveryDate))
OVER (PARTITION BY Department) as [90thpercentile]
from #Temp_Orders