建立工單發起統計表:
create
table
cvms_start_cates_statistics
(idnumber(15
)primary
keynot
null
, cate_id1
varchar2(50
), cate_id2
varchar2(50
), cate_id3
varchar2(50
), statistics_date
date
, order_total
number(15
) )建立工單發起序列號
create
sequence
cvms_start_cates_statistics_se
minvalue
1 maxvalue
999999999999
start
with
1 incrementby1
cache20;
建立工單發起觸發器
create
orreplace
trigger
cvms_start_cates_statistics_tr
before
insert
oncvms_start_cates_statistics
foreach
row begin
select
cvms_start_cates_statistics_se.nextval
into
:new.id
from
dual;
end;
查詢並統計每天的佔比
selectid,
identify_num
,order_num
,round
((identify_num
/(case
when
order_num=0
then
1else
order_num
end))*
100,
2)||
'%'from
cvms_end_order_identify
從乙個表中查詢出來的資料複製到另乙個表中:
insert
into
cvms_end_order_identify (
identify_date
,order_num
,identify_num)
select
to_date
(to_char
(start_time
,'yyyy-mm-dd'
),'yyyy-mm-dd'
),count
(*),
nvl(
sum(
case
when
result_count
>
0then
1else
0end),5
)ccfrom
cvms_end_work_order
group
byto_char
(start_time
,'yyyy-mm-dd'
)order
byto_char
(start_time
,'yyyy-mm-dd'
)desc
oracle中含有日期格式的插入:
insert
into
tb_start_order
values
(null
,'100171'
,'100282'
,'100289'
,to_date
('2014-06-23 08:02:06'
,'yyyy-mm-dd hh24:mi:ss'
),'214'
,'0.01%'
);帶分頁的查詢語句:
select *
from (select d.*, rownum as rn
from (select b.start_time, b.emp_code, b.order_text
from cvms_start_work_order_cates a, cvms_start_work_order b
where a.order_uuid = b.order_uuid
and 1 = 1
and cate_id3 = '100173'
and start_time >= to_date('2014-06-08 ', 'yyyy/mm/dd')
and start_time <= to_date('2014-06-20 ', 'yyyy/mm/dd')
and b.dept_code in ('n2221')
order by start_time desc
) dwhere rownum <= 10)
where rn >= 1
oracle中查詢兩個相鄰日期的資料:
select * from (
select version_name ,to_char(to_date(version_time,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') aa,
to_char(to_date(version_time,'yyyy-mm-dd hh24:mi:ss')+1,'yyyy-mm-dd hh24:mi:ss') bb
from version order by aa desc
) where rownum<2
7.查詢總的工單識別率:
select sum(tt.cc) ,sum(tt.bb) ,round((sum(tt.cc)/sum(tt.bb))*100,2)||'%' from(
select aa, '發起 ', bb, cc, cc/bb from (
select to_char(end_time,'yyyy-mm-dd') aa,sum(case when result_count>0 then 1 else 0 end) cc , count(*) bb from cvms_start_work_order
where end_time>=to_date('2014-05-18','yyyy-mm-dd') and end_time<=to_date('2014-05-26','yyyy-mm-dd') and result_count>0
group by to_char(end_time,'yyyy-mm-dd')
) ) tt
8.分類統計:
select cate_id1,cate_id2,cate_id3, cc,round((cc/sm)*100,2)||'%' from(
select cate_id1,cate_id2,cate_id3,count(*) as cc , ( select count(*) from cvms_start_work_order x , cvms_start_work_order_cates y
where x.order_uuid=y.order_uuid and x.start_time>= to_date('2014-05-15','yyyy-mm-dd') and x.end_time<= to_date('2014-05-22','yyyy-mm-dd') ) sm
from cvms_start_work_order a ,cvms_start_work_order_cates b
where a.order_uuid=b.order_uuid and a.start_time>= to_date('2014-05-15','yyyy-mm-dd') and a.end_time<= to_date('2014-05-22','yyyy-mm-dd')
group by cate_id1,cate_id2,cate_id3
)9.乙個表中乙個欄位xulie,表名為tb_a,xulie欄位的值就是0到9,可以重複,求出這些值不同的個數:
資料庫 Oracle中建立資料庫
create database lihua 網上的說法是 oracle中的例項只對應乙個資料庫,出現此種情況說明oracle資料庫處於mount 裝載 或open狀態,需要使用startup nomount語句進行狀態更改,或者是直接使用dbca的圖形介面來建立 注 經測試,startup nomo...
oracle中資料庫自增列實現
oracle可以自定義序列,但是如果想實現多表序列管理,可以用乙個很簡單的表去圍護 邏輯很簡單,新建表如下 兩個字段,分別記錄專案表名和表中對應的最大序列號 然後在新增序列時圍護這個表,就實現了專案中表序列的圍護了。create table create table table seq table ...
oracle資料庫自增
1 建立sequence create sequence seq seq1 minvalue 1 maxvalue 99999999999999 start with 1 increase by 1 chache 20 如果指定cache值,oracle就可以預先在記憶體裡面放置一些sequence...