我正在使用SQL Server 2014
我试图通过取一组中第90个百分位数的所有值的平均值来删除数据集中的一些噪音。这是查询:
SELECT
DISTINCT EventLocation,
PERCENTILE_CONT(.90)
WITHIN GROUP (ORDER BY (DATEDIFF(MINUTE, StartTime, EndTime)) ASC)
OVER (PARTITION BY EventLocation)
AS 'P90',
AVG(DATEDIFF(MINUTE, StartTime, EndTime))
OVER (PARTITION BY EventLocation)
AS 'Mean'
FROM MyTable
ORDER BY N DESC
目前有2个计算列:
PARTITION
人口数)PARTITION
人口数)我想添加另一列:
PARTITION
个群体中)< =第90个百分位值(PARTITION
个群体) 类似的东西:
AVG(DATEDIFF(MINUTE, StartTime, EndTime))
OVER (PARTITION BY EventLocation)
HAVING (DATEDIFF(MINUTE, StartTime, EndTime) <= [ 90th percentile value ])
AS 'Mean90'
我不确定如何处理这个问题,因为它引用了P90
中刚刚确定的第90个百分位值...可能是按组分组应用的用户定义函数,创建多个表并加入他们或其他什么。
答案 0 :(得分:0)
正如戈登所说,CTE是解决这类问题的常用方法。将原始查询的结果存储在CTE中,然后选择CTE的内容并使用您定义的列别名添加要完成的工作。
angular.forEach(myfilejob, function(fieldMapO) {
var count = 0;
angular.forEach(myfilejob, function(fieldMapI) {
if(fieldMapO.key == fieldMapI.key){
$scope.dupKey = fieldMapI.key;
count ++;
}
});
if(count>1){
$scope.dups = true;
// tried break , but didnt work
}
else{
$scope.dups = false;
}
});