Oracle数据库排名与不参与排名统计

参与排名

WITH table_a AS (
    SELECT 
        ROW_NUMBER() OVER (ORDER BY city DESC) AS 序号,
        a.* 
    FROM a 
    WHERE $[over_time >= to_date('${开始日期}', 'YYYY-MM-DD')] -- 开始日期
        AND $[over_time <= to_date('${结束日期}', 'YYYY-MM-DD')] -- 结束日期
),
table_tj AS (
    SELECT city AS 地市,COUNT(*) AS 总数,to_char(trunc(SYSDATE),'YYYY-MM-DD') AS 统计时间 FROM table_a GROUP BY city
)
SELECT main.*,dense_rank() over(order by main.总数 DESC) AS 排名 FROM (
    SELECT * FROM table_tj
    UNION ALL SELECT '全区' AS 地市,SUM("总数"),null FROM table_tj
  ) main
ORDER BY 
    CASE 地市
        WHEN '宁' THEN 1
        WHEN '林' THEN 2
        WHEN '柳' THEN 3
        WHEN '林' THEN 4
        WHEN '色' THEN 5
        WHEN '池' THEN 6
        WHEN '港' THEN 7
        WHEN '钦' THEN 8
        WHEN '梧' THEN 9
        WHEN '北' THEN 10
        WHEN '左' THEN 11
        WHEN '宾' THEN 12
        WHEN '贺' THEN 13
        WHEN '防' THEN 14
        WHEN '全区' THEN 15
    END;

不参与排名

WITH table_a AS (
    SELECT 
        ROW_NUMBER() OVER (ORDER BY city DESC) AS 序号,
        a.* 
    FROM a 
    WHERE $[over_time >= to_date('${开始日期}', 'YYYY-MM-DD')] -- 开始日期
    AND $[over_time <= to_date('${结束日期}', 'YYYY-MM-DD')] -- 结束日期
),
table_tj AS (
    SELECT city AS 地市, COUNT(*) AS 总数, to_char(trunc(SYSDATE),'YYYY-MM-DD') AS 统计时间 FROM table_a GROUP BY city
)
SELECT *
FROM (
    SELECT a.*,dense_rank() over(order by a.总数 desc) AS 排名 FROM table_tj a
    UNION ALL 
    SELECT '全区' AS 地市, SUM(总数) AS 总数,NULL, NULL AS 统计时间 FROM table_tj
) main
ORDER BY 
    CASE main.地市
        WHEN '宁' THEN 1
        WHEN '林' THEN 2
        WHEN '柳' THEN 3
        WHEN '林' THEN 4
        WHEN '色' THEN 5
        WHEN '池' THEN 6
        WHEN '港' THEN 7
        WHEN '钦' THEN 8
        WHEN '梧' THEN 9
        WHEN '北' THEN 10
        WHEN '左' THEN 11
        WHEN '宾' THEN 12
        WHEN '贺' THEN 13
        WHEN '防' THEN 14
        WHEN '全区' THEN 15
    END;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值