题目:
题解:
--这道题主要考察中位数的取法
SELECT
category_id,cast(sum(price)/count(1) as DECIMAL(16,2)) medprice
from(
SELECTcategory_id,price,rn,max(rn)over(partition by category_id) max_rn
from(SELECTcategory_id,price,row_number() over (partition bycategory_idorder byprice) rnfromsku_info) t
)t
where
--ceil(3.1415, 2)-->4 ; floor(3.1415, 2)-->3
--ceil 向上取整,奇数取中位数,偶数取靠右侧的位置;floor向下取整,奇数同上,偶数取靠左侧的位置rn in (ceil((max_rn+1)/2),floor((max_rn+1)/2))group by category_id;