oracle 取中位数方法

sql语句:
select median(fee_sum_before), avg(fee_sum_before),max(...), min(...)
  from ta_user_property
 
先把这些中位数,取出来。然后再填到语句里面,否则效率也低。顺便把平均数这些也取了。填到一张表里面

--select median (fee_sum_before)  from
 
用上面的语句取数据型变量的中位数
 
case when fee_sum_before >  median (fee_sum_before) then 1 else 0 end  xxx
 
 
select xxx, cust_status, count(*) from user_property.txt t
group by xxx, cust_status
 ====================================================
sql示例:select   case when fee_sum_before >  437 then 1 else 0 end  xxx,
         cust_status,
         count(*)
from     xxx
group by case when fee_sum_before >  437 then 1 else 0 end,
         cust_status;
 
上面的437就是用median(fee_sum_before)取出来的中位数的值。
==================================================
 
Row # xxx cust_status Expr1002 占比
1 1 0 40193 83%
2 1 1 3955 8%
3 1 2 4074 8%
4 2 0 1589 80%
5 2 1 169 9%
6 2 2 221 11%

=======
其中,占比指在当前cust_status下,该数值列中位于中位数之上或之下的用户数占该数值列所有用户数的百分比。
阅读(4602) | 评论(0) | 转发(0) |
0

上一篇:计算日期列距离当前日期的月数并更新到另一列

下一篇:sql语句搜集

你可能感兴趣的:(oracle 取中位数方法)