17,377
社区成员
发帖
与我相关
我的任务
分享
with t as
(
select 1 as id,'二区' as name ,'商用' as type,200 as cast from dual
union all
select 2 as id,'二区' as name ,'民用' as type,100 as cast from dual
union all
select 3 as id,'三区' as name ,'商用' as type,300 as cast from dual
union all
select 4 as id,'三区' as name ,'民用' as type,100 as cast from dual
union all
select 4 as id,'三区' as name ,'民用' as type,0 as cast from dual
)
select name,sum(case when type='商用' then 1 else 0 end) 商用总数,
sum(case when type='民用' then 1 else 0 end) 民用总数,sum(cast) 费用合计 from
(select * from t a where not exists(select 1 from t b where a.id=b.id and a.cast<b.cast )) t
group by name;
select 区域,sum(商用) as 商用总数,sum(民用) as 民用总数
from (
select 区域 ,类型 ,decode(类型,'商用',1,0) as 商用,decode(类型,'民用',1,0) as 民用
from (select distinct * from table )
)
group by 区域
select area, count(decode(way, '商用', way)) 商用, count(decode(way, '民用', way)) 民用, sum(fee) 总费用
from (select id, area, way, fee
from t
where t.rowid =
(select max(tt.rowid)
from t tt
where tt.id = t.id and tt.fee is not null))
group by area;
select 区域,sum(case when 类型='商用' then 1 else 0 end) "商用总数",sum(case when 类型='民用' then 1 else 0 end) "民用总数" from table group by 区域
select 区域,sum(商用) as 商用总数,sum(民用) as 民用总数
from (
select 区域 ,类型 ,decode(类型,'商用',1,0) as 商用,decode(类型,'民用',1,0) as 民用
from (select distinct * from table )
)
group by 区域