WITH table_a AS(SELECT
ROW_NUMBER()OVER(ORDERBY 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 GROUPBY city
)SELECT main.*,dense_rank()over(orderby main.总数 DESC)AS 排名 FROM(SELECT*FROM table_tj
UNIONALLSELECT'全区'AS 地市,SUM("总数"),nullFROM table_tj
) main
ORDERBYCASE 地市
WHEN'宁'THEN1WHEN'林'THEN2WHEN'柳'THEN3WHEN'林'THEN4WHEN'色'THEN5WHEN'池'THEN6WHEN'港'THEN7WHEN'钦'THEN8WHEN'梧'THEN9WHEN'北'THEN10WHEN'左'THEN11WHEN'宾'THEN12WHEN'贺'THEN13WHEN'防'THEN14WHEN'全区'THEN15END;
不参与排名
WITH table_a AS(SELECT
ROW_NUMBER()OVER(ORDERBY 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 GROUPBY city
)SELECT*FROM(SELECT a.*,dense_rank()over(orderby a.总数 desc)AS 排名 FROM table_tj a
UNIONALLSELECT'全区'AS 地市,SUM(总数)AS 总数,NULL,NULLAS 统计时间 FROM table_tj
) main
ORDERBYCASE main.地市
WHEN'宁'THEN1WHEN'林'THEN2WHEN'柳'THEN3WHEN'林'THEN4WHEN'色'THEN5WHEN'池'THEN6WHEN'港'THEN7WHEN'钦'THEN8WHEN'梧'THEN9WHEN'北'THEN10WHEN'左'THEN11WHEN'宾'THEN12WHEN'贺'THEN13WHEN'防'THEN14WHEN'全区'THEN15END;