with danke_bi_tmp.f_bi_lsq_ana_test as(
SELECTroom_code asid ,sign_date,price from 库名.表明
wherep_day = CURRENT_DATE+ INTERVAL'-1'dayandcity_name = '成都市'
)
/*
following向下寻找 preceding 向上寻找 1 preceding ====== 前两行
2 following ====== 后两行
current row ====== 当前行
unbounded preceding ====== 无上限
unbounded following ====== 无下限
*/
-- 房间首次出租房价近两次合同金额的平均值
selectid ,price,sign_date ,avg(price)over(orderbyid,sign_date rowsbetweencurrentrowand2following) asavg_price froma;
--房间租金最高值 根据排序可以desc /ASC 来设定是取最大值或者最小值
selectid ,price,sign_date, first_value(price)over(partitionbyid orderbyprice desc) fromdanke_bi_tmp.f_bi_lsq_ana_test a;
SELECTid ,price,sign_date,last_value(price)over(PARTITIONbyid orderbyprice ASCrangeBETWEEN unboundedprecedingandunboundedfollowing) fromdanke_bi_tmp.f_bi_lsq_ana_test a;
---- 把租金价格分成十个等级
selectid ,price,sign_date, ntile(10)over(orderbyprice) fromdanke_bi_tmp.f_bi_lsq_ana_test a;
---取房间下次出租的租金 lead(price,2) 下两行 lag(price,2)向上两行
selectid ,price,sign_date,lead(price)over(partitionbyid orderbyprice asc) fromdanke_bi_tmp.f_bi_lsq_ana_test a;
---房间价格 比本价格高的比例
selectid ,price,sign_date, cume_dist()over(orderbyprice desc) from danke_bi_tmp.f_bi_lsq_ana_test a;
来源:CSDN
作者:zzumarch
链接:https://blog.csdn.net/zzumarch/article/details/103986635