SQL Server 中位数、标准差、平均数

create table examines
(
    [e_id] [int] IDENTITY(1,1) NOT NULL,
    [dept_name] [nvarchar](200) NULL,
    [ph_score] [int] NULL
)


SELECT
   dept_name,
   AVG(sp) as '中位數'
FROM
(
   SELECT
      dept_name,
      cast(ph_score as decimal(5,2)) sp,
      ROW_NUMBER() OVER (
         PARTITION BY dept_name 
         ORDER BY ph_score ASC, e_id ASC) AS RowAsc,
      ROW_NUMBER() OVER (
         PARTITION BY dept_name 
         ORDER BY ph_score DESC, e_id DESC) AS RowDesc
   FROM examines SOH
) x
WHERE 
   RowAsc IN (RowDesc, RowDesc - 1, RowDesc + 1)
GROUP BY dept_name
ORDER BY dept_name;


select dept_name,STDEV(ph_score) as '標準差' from examines group by dept_name

select dept_name,avg(ph_score) as '平均數' from examines group by dept_name

 

转载于:https://www.cnblogs.com/mycing/p/4871733.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值