上面图片是打开客户端PLSQL devepoper的连接内容
进入页面后就可以进行相关的sql语句编写了
将几个结果放入一个表中
select 30+30 as 结果 from dual
union all
select 40+40 as 结果 from dual
union all
select 50+50 as 结果 from dual
将所要的结果统一输出
declare --开始申明
a_count integer; --a的交易量
b_count integer; --b的交易量
sum_count integer; --总的交易量
begin --开始执行
select sum(b.aaa) into a_count from (
select count(1) aaa
from gs.trace SUBPARTITION(SUB_DATA_20) t --SUB_DATA_20 是特定的按日期自己定义的变量 这里表是 2019-01-20,SUBPARTITION是指代从分区里面找
where t.date='2019-01-20'
and t.id in (M,N,X)
group by t.id) b ;
dbms_output.put_line('a的交易量:'|| a_count); --dbms_output.put_line 打印出结果
select tscount into sum_count from ig_count where tsdate='2019-01-20';
dbms_output.put_line('总的交易量:'|| sum_count);
select sum_count - a_count into b_count from dual; --在做计算的时候可以考虑用上dual表,这是个用于计算方便的表
dbms_output.put_line('剩下的的交易量:'|| sum_count);
end; --结束
使用case函数进行条件选择
with p as (
select (t.lasttime-t.creattime)24*60*60 as times from list t where
t.pk='aaa'
and t.creattime>to_date('2019-01-01 00:00:00','yyyy-MM-dd HH24:mi:ss')
and t.creattime<to_date('2019-02-01 00:00:00','yyyy-MM-dd HH24:mi:ss')
)
select
( case
when p.times<=1 then 'a~1秒内'
when p.times>1 and p.times <=2 then 'b~1-2秒内'
when p.times>2 then 'c~大于2秒'
end
) as des,
to_char(100*ROUND(count(1)/sum(count(1))over(),6),'fm999999990.0000')||'%' as percent,count(1)
from p
group by
case
when p.times<=1 then 'a~1秒内'
when p.times>1 and p.times <=2 then 'b~1-2秒内'
when p.times>2 then 'c~大于2秒'
end
order by des
输出结果
DES PERCENT COUNT(1)
1 a~1秒内 10.3456% 1111111
2 b~1-2秒内 20.2345% 2222222
3 c~大于2秒 30.1234% 3333333