測試統計報表SQL常用總結

2021-10-05 15:14:59 字數 2139 閱讀 4487

插入錶值 insert into…values…

insert

into 表名x(

'列名1'

,'列名2'

,'列名3'..

.)values(''

,'',''

...)

where條件剔除與匹配

where  x.nvl(biz_cd,

'0')

notin

('2817'

,'2818'

)--存在空值時用nvl補全

and x.bank_acct_num not

like

'%10071426880005__'

--like

and x.nvl(entrust_id,

'1')

!='2019071913002'

and(x.due_dt between

'20200422'

and'20200430'

)--between and

-- and (x.due_dt>'20200422' or x.due_dt='00000101') --or

--年日均 = ∑ 金額 * 存續天數 / 實際天數

--收益率 = ∑ 執行利率 * 年日均 /年日均

-- 存續天數= min(到期日,季末時點)-max(起息日,資料日期)

--to_date( ,'yyyy-mm-dd')

--case when 條件 then 結果 else 結果 end

--sign() 結果值正數輸出1 負數輸出-1 相等輸出0

--decode(條件,匹配值1,輸出值1,輸出值2)

--cast( as )

select cast(

sum( t.int_rate *

(t.rmb_bal_amt/

100000000)*

(to_date(

case

when

(t.due_dt<

'20200630'

)then t.due_dt else

'20200630'

end,

'yyyy-mm-dd')-

to_date(decode(sign(t.int_start_dt-

'20200422'),

1,t.int_start_dt,

'20200422'),

'yyyy-mm-dd'))

/(to_date(

'20200630'

,'yyyy-mm-dd'

)- to_date(

'20200422'

,'yyyy-mm-dd'))

)*1./

sum(t.rmb_bal_amt/

100000000

*(to_date(

case

when

(t.due_dt<

'20200630'

)then t.due_dt else

'20200630'

end,

'yyyy-mm-dd')-

to_date(decode(sign(t.int_start_dt-

'20200422'),

1,t.int_start_dt,

'20200422'),

'yyyy-mm-dd'))

))/(to_date(

'20200630'

,'yyyy-mm-dd'

)- to_date(

'20200422'

,'yyyy-mm-dd'))

asdecimal(8

,4))收益率

from

(select

*from v_b_promanage)t --檢視

where statistics_dt=

'20200422'

--資料日20200422,故以2023年第二季度收益率為例

統計count

select

count(*

)from 表名x

關於統計報表常用sql

1 根據條件查總數 select count all sum,if sum if problem state in 1,2 1,0 is null,0,sum if problem state in 1,2 1,0 problem num,if sum if problem state 3,1,0 ...

統計報表 sql統計語句

需要資料統計頁面,肯定需要匯出資料,於是,邊學邊寫,完成了一段sql 最早的版本是這樣的 分三條sql查出三種不同的狀態的記錄數 總記錄,未支付,已支付 select count as recordcount from t record where createtime 2019 01 01 00 ...

報表統計 sql面試題

有3張表 學生表 s 字段 學生編號 學生姓名 課程表 c 字段 課程編號 課程名稱 成績表 sc 字段 學生編號 課程編號 分數 需要實現最終效果如下 後面有些課程省略沒有截圖了 實現的方法 方法一 select max s.name as姓名,max case when sc.cid 1 the...