需求是对 SPBM 、SPMC 分组,计算 ZJ/CKSL 最小值及其条数,最大值及其条数, 使用的数据库 Oracle 。
SELECT SPBM,SPMC, round( MIN(DJ),5) AS MIN_DJ, sum(CASE WHEN min_rn = 1 THEN sl ELSE 0 END) AS MIN_SL, round( MAX(DJ),5) AS MAX_DJ, sum(CASE WHEN max_rn = 1 THEN sl ELSE 0 END) AS MAX_SL from
(
SELECT SPBM, SPMC, ZJ/CKSL as DJ , count(*) as sl,
ROW_NUMBER() OVER (PARTITION BY SPBM,SPMC ORDER BY ZJ/CKSL ASC) AS min_rn,
ROW_NUMBER() OVER (PARTITION BY SPBM,SPMC ORDER BY ZJ/CKSL DESC) AS max_rn
FROM SP
GROUP BY SPBM, SPMC,ZJ/CKSL
)
WHERE min_rn = 1 OR max_rn = 1
GROUP BY SPBM,SPMC
从运维导出的结果 excel 里发现 MIN_SL,MAX_SL 这两个数量存在小数,不知道为啥?
1
Paracosm 2023-06-07 14:48:22 +08:00
数据不匹配或者隐式转换?
|
2
DOMO 2023-06-07 15:38:14 +08:00
把 count 结果导出来手动加加看呢
|
3
HankAviator 2023-06-07 22:10:19 +08:00
ZJ/CKSL 的值拉出来看看?
|