1. 程式人生 > >Ordele的decode函式的用法

Ordele的decode函式的用法

一、查詢序列的下一值

(select decode(max(RECORD_VOLTAGE_ID),null,0,max(RECORD_VOLTAGE_ID)+1) RECORD_VOLTAGE_ID from RECODR_MAINTAIN_VOLTAGE)

二、排序置前

 select * from tb order by decode(blogid,3,1,2), blogid;

BLOGID值為3的那條記錄被轉換為了1,而其他的記錄都是2。

有時候我們需要根據條件來進行統計:

三、通過decode判斷並生成設定類別列,

不用再資料庫中多增加類別欄位

select us.*
          from (SELECT u.*,
                       decode(me.member_id, NULL, 0, 1) AS IS_TRUE,
                       decode(jo.join_id, NULL, 0, 1) AS IS_JOIN
                  FROM CT_USER u
                  LEFT JOIN member me
                    ON u.user_id = me.id
                  LEFT JOIN pb_join jo
                    ON u.user_id = jo.id ) us

四、設定識別符號

oracle decode統計關聯表是否有資料

(select a.emer_id,
       a.CHECK_METHOD,
       a.IS_CLOSED,
       (select decode(count(*), 0, '0', '1')
          from GL_EMER e
         where e.emer_id = a.emergency_id) as CHECK_STATUS
  from GL_EMERGENCY a)b

五、decode進行統計運算

 create or replace view v_wjx_hz as
select "TERRITORIALITYUNIT","YEAR","MONTH","WORKID","DEVICE_ID","DEVICE_NAME","DEVICE_LOCNO","DEV_CLASS_ID","DEVICE_PRESSURE_LEVEL","T_JXZS","T_JTDX","T_ZXXX","T_TS","T_GHFT","T_GHPM","T_FKD","T_OXH","T_ZHQPT","G_JXZS","G_KG","G_PW","G_Z","G_BZ","G_GHLXS","G_GHOXH","F_FMWH","F_FMBWH","F_CLWH","F_CLBWH","F_QNJZQXY","F_QNJZRHY","F_QNJZMFZ" from
(
select t1.territorialityunit,
       t1.year,
       t1.month,
       t1.workid,
       t1.device_id,
       t1.device_name,
       t1.device_locno,
       t1.dev_class_id,
       t1.device_pressure_level,
       t2.t_jxzs,
       t2.t_jtdx,
       t2.t_zxxx,
       t2.t_ts,
       t2.t_ghft,
       t2.t_ghpm,
       t2.t_fkd,
       t2.t_oxh,
       t2.t_zhqpt,
       t3.g_jxzs,
       t3.g_kg,
       t3.g_pw,
       t3.g_z,
       t3.g_bz,
       t3.g_ghlxs,
       t3.g_ghoxh,
       t4.f_fmwh,
       t4.f_fmbwh,
       t4.f_clwh,
       t4.f_clbwh,
       t4.f_qnjzqxy,
       t4.f_qnjzrhy,
       t4.f_qnjzmfz
  from eam_wjx_result_tb t1
  left join (select  decode(t_jtdx,null,0,t_jtdx)+decode(t_zxxx,null,0,t_zxxx)+decode(t_ts,null,0,t_ts) as t_jxzs, t5.* from (select workid,
                    sum(case jxfs
                          when '1' then
                           1
                        end) as t_jtdx,
                    sum(case jxfs
                          when '2' then
                           1
                        end) as t_zxxx,
                    sum(case jxfs
                          when '3' then
                           1
                        end) as t_ts,
                    sum(ghft) as t_ghft,
                    sum(ghpm) as t_ghpm,
                    sum(fkd) as t_fkd,
                    sum(oxh) as t_oxh,
                    sum(zhqpt) as t_zhqpt
               from eam_wjx_result_tyq_tb
              group by workid) t5) t2
    on t1.workid = t2.workid
  left join (select decode(g_kg,null,0,g_kg)+decode(g_pw,null,0,g_pw) as g_jxzs, t6.* from (select workid,
                    sum(case jxfs
                          when '1' then
                           1
                        end) as g_kg,
                    sum(case jxfs
                          when '2' then
                           1
                        end) as g_pw,
                    sum(case lxsfz
                          when '3' then
                           1
                        end) as g_z,
                    sum(case lxsfz
                          when '4' then
                           1
                        end) as g_bz,
                    sum(ghlxs) as g_ghlxs,
                    sum(ghoxh) as g_ghoxh
               from eam_wjx_result_glq_tb
              group by workid) t6) t3
    on t1.workid = t3.workid
  left join (select workid,
                    sum(case fmsfwh
                          when '1' then
                           1
                        end) as f_fmwh,
                    sum(case fmsfwh
                          when '0' then
                           1
                        end) as f_fmbwh,
                    sum(case clxsfwh
                          when '1' then
                           1
                        end) as f_clwh,
                    sum(case clxsfwh
                          when '0' then
                           1
                        end) as f_clbwh,
                    sum(qnjzqxy) as f_qnjzqxy,
                    sum(qnjzrhy) as f_qnjzrhy,
                    sum(qnjzmfz) as f_qnjzmfz
               from eam_wjx_result_fm_tb
              group by workid) t4
    on t1.workid = t4.workid
union all
select '合計' territorialityunit,
       null year,
       month,
       null workid,
      null device_id,
      null device_name,
       null device_locno,
     null dev_class_id,
       null device_pressure_level,
       sum(t2.t_jxzs),
       sum(t2.t_jtdx),
        sum(t2.t_zxxx),
        sum(t2.t_ts),
        sum(t2.t_ghft),
       sum( t2.t_ghpm),
        sum(t2.t_fkd),
        sum(t2.t_oxh),
       sum( t2.t_zhqpt),
       sum( t3.g_jxzs),
       sum( t3.g_kg),
...

統計不同類別的人數

select sum(p.total) total,sum(p.Committee) Committee,sum(p.general) general,sum(p.branch) branch,sum(p.pmgroup) pmgroup from (select t.ORG_NAME as orgName,
       t.org_id as OrgId,
       count(t.party_org_id) as total,
       count(DECODE(t.ORG_TYPE, '1', 1)) as partyCommittee,
       count(DECODE(t.ORG_TYPE, '2', 1)) as generalBranch,
       count(DECODE(t.ORG_TYPE, '3', 1)) as branch,
       count(DECODE(t.ORG_TYPE, '4', 1)) as pmgroup
  from pb_party_org t
 inner join (SELECT *
               FROM pb_org
              START WITH party_org_id in ('10')
             CONNECT BY nocycle PRIOR org_id = last_org) po
    on t.org_id = po.org_id
 group by t.ORG_NAME, t.org_id) p

相關推薦

glViewport函式用法

一、 其函式原型為glViewport(GLint x,GLint y,GLsizei width,GLsizei height) x,y 以畫素為單位,指定了視窗的左下角位置。 width,height表示視口矩形的寬度和高度,根據視窗的實時變化重繪視窗。 二、 在預設情況下,視口被設定為佔據視窗

ROW_NUMBER() OVER()函式用法;(分組,排序),partition by (轉)

1、row_number() over()排序功能: (1) row_number() over()分組排序功能:      在使用 row_number() over()函式時候,over()裡頭的分組以及排序的執行晚於 where group by  order

numpy函式:tile函式用法

tile函式位於python模組 numpy.lib.shape_base中,他的功能是重複某個陣列。比如tile(A,n),功能是將陣列A重複n次,構成一個新的陣列 from numpy import * #initialize the array a = [0,1,2]

Oracle單行函式用法

  單行函式分為五種型別:字元函式、數值函式、日期函式、轉換函式、通用函式。   1.字元函式:   對於輸入的字元轉換為需要轉為的字元或數值。   upper()大寫        --小寫字母轉為大寫字母      --對於表指定

C語言幾個函式用法小結

1.char *ultoa(unsigned long value,char *string,int radix)  將無符號整型數value轉換成字串並返回該字串,radix為轉換時所用基數  2.char *ltoa(long value,char *string,i

numpy中flatten()函式用法

flatten是numpy.ndarray.flatten的一個函式,其官方文件是這樣描述的: ndarray.flatten(order='C') Return a copy of the array collapsed into one dimension. Parameters:

strtol函式用法

之前想用C寫MD5函式用法,中間設計大量進位制轉換的內容,於是就查到了strtol這個函式 但是發現之前對其認識上有一些偏頗,所以把它的用法記錄下來 strtol是一個C語言函式,作用就是將一個字串轉換為長整型long,其函式原型為 long int strtol (const

getline() 函式用法

本文轉自:http://blog.sina.com.cn/s/blog_60263c1c0101ck25.html 學習C++的同學可能都會遇到一個getline()函式,譬如在C++premer中,標準string型別第二小節就是“用getline讀取整行文字”。書上給的程式如下:

PHP array_pad函式用法

<?php //填充陣列到制定長度 $array = [1,2,3,4]; $array1 = [ [1],[2],[3],[4] ]; print_r(array_pad($array,6, 'abc')); //執行結果:Array ( [0] => 1 [1] =

np.nonzero()函式用法

返回陣列中不為0的元素的下標。 陣列中元素可為布林、整型和浮點型,返回值為元祖 一.一維陣列 1.陣列元素為布林型別 a=np.array([True,False,True,False]) b=np.nonzero(a) print(b) 輸出結果為(array([0, 2], dtype

python中的print輸出函式用法總結

【時間】2018.10.12 【題目】python中的print輸出函式用法總結   一、直接輸出 無論什麼型別,數值,布林,列表,字典...都可以直接輸出,或者先賦值給變數,再輸出。     二、格式化輸出 下面是《Python基

Python中split()函式用法和例項

一、描述 split()通過指定分隔符對字串進行切片,如果引數num 有指定值,則僅分隔 num 個子字串 函式形式:str.split(str="", num=string.count(str)) 引數: str -- 分隔符,預設為所有的空字元,包括空格、換行(\n)、製表

numpy中:tile函式用法

tile函式位於python模組 numpy.lib.shape_base中,他的功能是重複某個陣列。比如tile(A,n),功能是將陣列A重複n次,構成一個新的陣列,我們還是使用具體的例子來說明問題 ①先來引入numpy下的所有方法 from numpy import *

【 MATLAB 】nextpow2 函式用法之 Optimize FFT with Padding

您可以使用nextpow2來填充傳遞給fft的訊號。 這樣做可以在訊號長度不是2的精確冪次時加速FFT的計算。 Optimize FFT with Padding   下面這個例子展示了 使用填充優化FFT的案例,通過使用函式nextpow2完成: clc c

ROW_NUMBER() OVER()函式用法詳解 (分組排序 例子多)

語法格式:row_number() over(partition by 分組列 order by 排序列 desc) row_number() over()分組排序功能: 在使用 row_number() over()函式時候,over()裡頭的分組以及排序的執行晚於 wher

C函式之memcpy 函式用法

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

srand()以及rand()函式用法

srand()就是給rand()提供種子seed 如果srand每次輸入的數值是一樣的,那麼每次執行產生的隨機數也是一樣的, srand(n) for(10) rand()也就是說,以一個固定的數值作為種子是一個缺點。 通常的做法是  以這樣一句程式碼

Python的Request函式用法

目錄 傳送請求 POST 請求: 其他請求: 傳遞 URL 引數 響應內容 二進位制響應內容 JSON 響應內容 原始響應內容 定製請求頭 更加複雜的 POST 請求 POST一個多部分編碼(Multipart-Encoded)的檔案 響應狀態碼

linux之select函式用法詳解

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

matlab中的mvnrnd函式用法

使用matlab來實現: clear all;close all; clc; % 第一組資料 mul=[0,0]; % 均值 S1=[.1 0;0 .1]; % 協方差 data1=mvnrnd(mul, S1, 100); % 產生高斯分佈資料 % 第二組資料 mu2=[1.25 1.25