sql code:
select rg, count(2) stcd
from (select t2.*,
(case
when y < 10 then
'0~10'
when y >= 10 and y <= 24.9 then
'10~24.9'
when y >= 25 and y <= 49.9 then
'25~49.9'
when y >= 50 and y <= 99.9 then
'50~99.9'
when y >= 100 and y <= 199.9 then
'100~199.9'
when y >= 200 and y <= 299.9 then
'200~299.9'
else
TO_CHAR(y)
end) rg
from (select t1.*, d.ADDVNM, d.ADDVCD, b.STNM
from (select r.stcd, sum(r.dyp) y
from ST_PPTN_R_LOC r
where r.dyp is not null
and r.tm BETWEEN
TO_DATE('2015-05-02 12:20:12',
'yyyy/mm/dd hh24:mi:ss') AND
TO_DATE('2018-05-02 12:20:12',
'yyyy/mm/dd hh24:mi:ss')
group by r.STCD) t1,
ST_STBPRP_B_LOC b,
ST_ADDVCD_D_LOC d
where t1.stcd = b.STCD
and b.ADDVCD = d.ADDVCD) t2) t3
group by rg;
效果图:
数据表:
sql结果:
3 个解决方案
#1
这个效果?
with a as
(select '张三' name, '空洞' dept, 209 sal
from dual
union all
select '灭绝' name, '峨眉' dept, 253 sal
from dual
union all
select '李四' name, '空洞' dept, 271 sal
from dual
union all
select '令狐冲' name, '华山' dept, 932 sal
from dual
union all
select '岳灵珊' name, '华山' dept, 432 sal
from dual
union all
select '任盈盈' name, '华山' dept, 832 sal
from dual)
select count(distinct dept) 部门数量, count(distinct name) 人员数量, flag
from (select name,
dept,
case
when sal between 200 and 300 then
'200~300'
when sal between 301 and 500 then
'300~500'
else
'800以上'
end flag,
sal
from a)
group by flag
#2
能留个联系方式,请教下吗?
#3
咋查询的结果跟你不一样呢?站数量和县数量还是一样??
数据表:
#1
这个效果?
with a as
(select '张三' name, '空洞' dept, 209 sal
from dual
union all
select '灭绝' name, '峨眉' dept, 253 sal
from dual
union all
select '李四' name, '空洞' dept, 271 sal
from dual
union all
select '令狐冲' name, '华山' dept, 932 sal
from dual
union all
select '岳灵珊' name, '华山' dept, 432 sal
from dual
union all
select '任盈盈' name, '华山' dept, 832 sal
from dual)
select count(distinct dept) 部门数量, count(distinct name) 人员数量, flag
from (select name,
dept,
case
when sal between 200 and 300 then
'200~300'
when sal between 301 and 500 then
'300~500'
else
'800以上'
end flag,
sal
from a)
group by flag
#2
能留个联系方式,请教下吗?
#3
咋查询的结果跟你不一样呢?站数量和县数量还是一样??
数据表: