当前位置:  开发笔记 > 编程语言 > 正文

使用PERCENTILE_DISC和Aggregate函数

如何解决《使用PERCENTILE_DISC和Aggregate函数》经验,为你挑选了1个好方法。



1> getglad..:

看起来使用over子句,从而创建一个"窗口函数",将聚合函数与select语句分开.

SELECT
    Distinct [DataPoint],
    MIN([Value]) OVER (PARTITION BY [DataPoint]) AS [Value MIN],
    MAX([Value]) OVER (PARTITION BY [DataPoint]) AS [Value MAX],
    AVG([Value]) OVER (PARTITION BY [DataPoint]) AS [Value AVG],
    PERCENTILE_DISC(0.5)
        WITHIN GROUP 
        (ORDER BY [Value])
        OVER 
        (PARTITION BY [DataPoint])
        AS MedianCont
    FROM [Table] AS [Table]
    WHERE ([DataPoint]
        IN (
            ...
        )
    )

推荐阅读
路人甲
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有