gpt4 book ai didi

sql - TSL/SQL PERCENTILE_CONT 应返回 1 条记录

转载 作者:行者123 更新时间:2023-12-04 23:51:25 25 4
gpt4 key购买 nike

我正在处理一个 T-SQL 查询(我正在运行一个 SQL Server 数据库),该查询应该根据值列表计算中位数。查询如下所示:

SELECT 
PERCENTILE_CONT(0.5) OVER (ORDER BY age) as Age
FROM
peopleDB
WHERE
<expressions>;

数据库有 100 行。查询返回中位数(相同的值)100 次,但我的目标是只返回一次。我一直在尝试以多种方式使用 DISTINCTGROUP BY 但每次都返回语法错误。数据库目前不支持 DISTINCT

我是否有可能忽略了一些明显的东西?

最佳答案

我从未听说过 TSL。但是,以下方法之一可能会起作用:

SELECT PERCENTILE_CONT(0.5) OVER (ORDER BY age) as Age
FROM peopleDB
WHERE <expressions>
limit 1;

SELECT top 1 PERCENTILE_CONT(0.5) OVER (ORDER BY age) as Age
FROM peopleDB
WHERE <expressions>;

SELECT max(PERCENTILE_CONT(0.5) OVER (ORDER BY age)) as Age
FROM peopleDB
WHERE <expressions>;

select max(age)
from (SELECT top 1 PERCENTILE_CONT(0.5) OVER (ORDER BY age) as Age
FROM peopleDB
WHERE <expressions>
) t

关于sql - TSL/SQL PERCENTILE_CONT 应返回 1 条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17286973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com