Oracle 数据库 常见SQL语法

简介: Oracle 数据库 常见SQL语法

1:显示某一年某月的数据(包括不存在的数据)我如果想查都要查出来

SELECT 
    '2019' AS 年度,
    a.month AS 月份, 
    NVL(b.调试台设备利用率, 0) AS 调试台设备利用率,
    NVL(b.震动台设备设备利用率, 0) AS 震动台设备设备利用率,
    NVL(b.电装标贴设备利用率, 0) AS 电装标贴设备利用率,
    NVL(b.调试台故障率, 0) AS 调试台故障率,
    NVL(b.震动台故障率, 0) AS 震动台故障率,
    NVL(b.电装标贴故障率, 0) AS 电装标贴故障率
FROM (
    SELECT TO_CHAR(ADD_MONTHS(TO_DATE(CONCAT('2023','0101'), 'YYYYMMDD'), LEVEL - 1), 'fmMonth') AS month
    FROM DUAL
    CONNECT BY LEVEL <= 12
) a
LEFT JOIN (
    SELECT 
        SUBSTR(STAT_TIME,1,4) AS 年份,
        MONTH_DATA || '月' AS 月份,
        NVL(DEBUG_EQUIPMENT_TREND, 0) AS 调试台设备利用率 ,
        NVL(SHAKING_EQUIPMENT_TREND, 0) AS 震动台设备设备利用率 , 
        NVL(STICKERS_EQUIPMENT_TREND, 0) AS 电装标贴设备利用率,
        NVL(DEBUG_EQUIPMENT_FAILURERATE, 0) AS 调试台故障率,
        NVL(SHAKING_EQUIPMENT_FAILURERATE, 0) AS 震动台故障率,
        NVL(STICKER_EQUIPMENT_FAILURERATE, 0) AS 电装标贴故障率  
    FROM BRAIN.DM_EQUIPMENTUTILIZATION_TREND
    WHERE ORG_NAME = '17所' AND  SUBSTR(STAT_TIME,1,4) = '2019'
) b ON a.month = b.月份
ORDER BY a.month;
--拼接月份的另外一种写法  使用concat 函数,进行字符串拼接
concat(TO_CHAR(TO_DATE(B.DATEVALUE, 'YYYYMM'), 'MM'),'月')

结果:

4a4b44095d5e4c63937d7702a58a4faf.png

2:查询当前年以及往后俩年的数据

select to_char(years) 年份 from 
(select TO_CHAR(Sysdate, 'YYYY') - level + 1 years from dual connect by level <= 3)

结果:

a554a9ce284e4f8ea06aed922be52dc7.png

3:查询当前年前5年的年份

SELECT TO_CHAR(ADD_MONTHS
(to_date( ${年度选择} ,'yyyy'), (1 - ROWNUM)*12), 'YYYY') YEAR_LIST 
FROM DUAL CONNECT BY ROWNUM <= 5
// ${年度选择}     输入你想要的字符串年份,获取当年前五年

c6fad816b74544299452146d65c8f785.png

4:查询当前年的数据(不存在则显示 0),

SELECT A.month AS 每年月份 ,
nvl(A.目标值,0) AS 目标值, 
NVL(B.完成率,0) AS 完成率 
from(
SELECT
  TO_CHAR(ADD_MONTHS(TO_DATE(CONCAT( ${年度选择}  ,'0101'), 'YYYYMMDD'), LEVEL - 1), 'mm') || '月' AS month,
  ROUND(LEVEL / 12.0 * 100, 2) AS 目标值
FROM
  DUAL
CONNECT BY
  LEVEL <= 12) A
left join 
(SELECT 
NVL(REFORM_TASK_COM_RATE,0) AS 完成率,
SUBSTR(STAT_TIME,5,6)|| '月'  AS 每年月份
FROM  BRAIN.DM_ZHGL_REFORM_TASK_INFO 
WHERE  SUBSTR(STAT_TIME,1,4) =   ${年度选择}  ) 
B 
ON A.month = B.每年月份

结果:a84b02a0404d4c51bde8e1ef115a76d9.png

5:  3/14_设备情况_各类设备停机率年度趋势

SELECT 
 '' AS 唯一标识,
 a.ORGCODE AS 单位编号,
 a.ORGNAME AS 单位名称,
 a.ORGMANLEVEL AS 单位层级,
 NVL(a.统计日期类别,0) AS  统计日期类别,
 NVL(b.DATA_DATE,0) AS 统计日期,
 NVL(b.调试台故障率,0) AS 调试台故障率 ,
 NVL(b.电装标贴故障率,0) AS 电装标贴故障率,
 NVL(b.震动台故障率,0) AS  震动台故障率,
 NVL(b.CREATE_TIME,0) AS 创建时间,
 sysdate AS 更新时间
 FROM (
  SELECT ORGCODE , ORGNAME ,ORGMANLEVEL,
 '02' AS 统计日期类别
 FROM BRAIN.DIM_ORG WHERE ORGCODE = 'INST17'
 ) a 
 LEFT JOIN(
 SELECT  
 ORG_NO,
 ORG_NAME,
 DATA_DATE,
 NVL(a.调试台故障率,0) AS 调试台故障率,
 NVL(a.电装标贴故障率,0) AS 电装标贴故障率,
 NVL(a.震动台故障率,0) AS 震动台故障率,
 CREATE_TIME 
  FROM ( 
   SELECT ROW_NUMBER() OVER(PARTITION BY ORG_NO,TO_CHAR(DATA_DATE, 'YYYYMM') 
ORDER BY DATA_DATE DESC, CREATE_TIME DESC) rn,
          ORG_NO,
          ORG_NAME,
          TO_CHAR(DATA_DATE,'YYYYMM') AS DATA_DATE ,
          decode(DZBT_SBJHKDSJ,0,0,round((NVL(DZBT_GZTJSJ,0) / DZBT_SBJHKDSJ),2)) AS 调试台故障率,
          decode(TST_SBJHKDSJ,0,0,round((NVL(TST_GZTJSJ,0) / TST_SBJHKDSJ),2)) AS 电装标贴故障率,
          decode(ZDT_SBJHKDSJ,0,0,round((NVL(ZDT_GZTJSJ,0) / ZDT_SBJHKDSJ),2)) AS 震动台故障率,
          CREATE_TIME
          FROM BRAIN.DS_EQUIPMENT_GZLINFO
            ) a
 where a.rn = 1
 ) b
 ON a.ORGNAME = b.ORG_NAME

结果:

2f42a6ed96ec4399a521723be09375af.png

5:  3/14_设备情况_设备故障指标统计

SELECT 
'' AS 唯一标识,
a.ORGCODE AS 单位编号,
a.ORGNAME AS 单位名称,
a.ORGMANLEVEL AS 单位层级,
b.数据日期 AS 数据日期,
a.统计日期类别 AS 统计日期类别,
b.电装标贴总数 AS 电装标贴总数,
b.调试台总数 AS 调试台总数,
b.振动台总数 AS 振动台总数,
b.电装标贴设备发生故障设备数量 AS 电装标贴设备发生故障设备数量,
b.调试台设备发生故障设备数量 AS  调试台设备发生故障设备数量,
b.振动台设备发生故障设备数量 AS  振动台设备发生故障设备数量,
b.设备电装表贴发生故障总数 AS 设备电装表贴发生故障总数,
b.设备调试台发生故障总数 AS 设备调试台发生故障总数,
b.设备振动台发生故障总数 AS 设备振动台发生故障总数,
b.设备利用率 AS 设备利用率,
b.设备故障率 AS 设备故障率,
sysdate AS  更新时间, 
b.CREATE_TIME AS 创建时间
FROM (
SELECT 
ORGCODE,
ORGNAME,
ORGMANLEVEL,
'04' AS 统计日期类别
FROM BRAIN.DIM_ORG WHERE ORGCODE = 'INST17'
 ) a 
LEFT JOIN(
SELECT 
  a.机构编号 AS 机构编号,
  a.机构名称 AS 机构名称,
  a.电装标贴总数 AS 电装标贴总数,
  a.调试台总数 AS 调试台总数,
  a.振动台总数 AS 振动台总数,
  a.电装标贴设备发生故障设备数量 AS 电装标贴设备发生故障设备数量,
  a.调试台设备发生故障设备数量 AS 调试台设备发生故障设备数量,
  a.振动台设备发生故障设备数量 AS 振动台设备发生故障设备数量,
  a.设备电装表贴发生故障总数 AS 设备电装表贴发生故障总数 ,
  a.设备调试台发生故障总数 AS 设备调试台发生故障总数,
  a.设备振动台发生故障总数 AS 设备振动台发生故障总数,
  a.设备利用率 AS 设备利用率,
  a.设备故障率 AS 设备故障率,
  a.LATEST_VALUE AS 最新时间,                          
  a.数据日期 AS 数据日期,
  a.CREATE_TIME AS CREATE_TIME
  FROM ( 
   SELECT ROW_NUMBER() OVER(PARTITION BY ORG_NO,TO_CHAR(DATA_DATE, 'YYYY') 
ORDER BY DATA_DATE DESC, CREATE_TIME DESC) rn,
               ORG_NO 机构编号,
               NVL(DENSO_NUM,0) AS 电装标贴总数,
               NVL(COMMISSION_BENCH_NUM,0) AS 调试台总数,
               NVL(VIBRATION_TABLE_NUM,0) AS 振动台总数,
               NVL(DZBT_FS_GZ_EQUIPMENT_NUM,0) AS 电装标贴设备发生故障设备数量,
               NVL(TST_FS_GZ_EQUIPMENT_NUM,0) AS 调试台设备发生故障设备数量,
               NVL(ZDT_FS_GZ_EQUIPMENT_NUM,0) AS 振动台设备发生故障设备数量,
               NVL(DZBT_EQUIPMENT_GZ_TOTAL,0) AS 设备电装表贴发生故障总数,
               NVL(TST_EQUIPMENT_GZ_TOTAL,0) AS 设备调试台发生故障总数,
               NVL(ZDT_EQUIPMENT_GZ_TOTAL,0) AS 设备振动台发生故障总数,  
               NVL(EQUIPMENT_ALL_LYV,0) AS 设备利用率,
               NVL(EQUIPMENT_ALL_GZL,0) AS 设备故障率,
               NVL(DATA_DATE,0) AS LATEST_VALUE,
               ORG_NAME AS 机构名称,
               TO_CHAR(DATA_DATE, 'YYYY') AS 数据日期,
               NVL(CREATE_TIME,0) AS CREATE_TIME
          FROM BRAIN.DS_PRODUCT_EQUIP_INFO 
            ) a
 where a.rn = 1
 )b 
 ON a.ORGNAME = b.机构名称

6: 设备情况故障分析

SELECT 
     ${年度}  AS 年度,
    a.month AS 月份, 
    NVL(b.调试台设备利用率, 0) AS 调试台设备利用率,
    NVL(b.震动台设备设备利用率, 0) AS 震动台设备设备利用率,
    NVL(b.电装标贴设备利用率, 0) AS 电装标贴设备利用率,
    NVL(b.调试台故障率, 0) AS 调试台故障率,
    NVL(b.震动台故障率, 0) AS 震动台故障率,
    NVL(b.电装标贴故障率, 0) AS 电装标贴故障率
FROM (
    SELECT TO_CHAR(ADD_MONTHS(TO_DATE(CONCAT('2022','0101'), 'YYYYMMDD'), LEVEL - 1), 'fmMonth') AS month                         //去掉0
    FROM DUAL
    CONNECT BY LEVEL <= 12
) a
LEFT JOIN (
    SELECT 
        SUBSTR(STAT_TIME,1,4) AS 年份,
        MONTH_DATA || '月' AS 月份,
        NVL(DEBUG_EQUIPMENT_TREND, 0) AS 调试台设备利用率 ,
        NVL(SHAKING_EQUIPMENT_TREND, 0) AS 震动台设备设备利用率 , 
        NVL(STICKERS_EQUIPMENT_TREND, 0) AS 电装标贴设备利用率,
        NVL(DEBUG_EQUIPMENT_FAILURERATE, 0) AS 调试台故障率,
        NVL(SHAKING_EQUIPMENT_FAILURERATE, 0) AS 震动台故障率,
        NVL(STICKER_EQUIPMENT_FAILURERATE, 0) AS 电装标贴故障率  
    FROM BRAIN.DM_EQUIPMENTUTILIZATION_TREND
    WHERE ORG_NAME = '17所' AND SUBSTR(STAT_TIME,1,4) =  ${年度} 
) b ON a.month = b.月份
ORDER BY a.month

7: 查询1年个的12个月下的数据

SELECT TO_CHAR(ADD_MONTHS(TO_DATE(CONCAT('2022','0101'), 'YYYYMMDD'), LEVEL - 1), 'fmMonth') AS month                //去掉 0
    FROM DUAL
    CONNECT BY LEVEL <= 12

结果:

065661f7d77d4ec08894d9f29850797d.png

8:  3种不同种类的设备数量,按照每条取最新值, 一年一共有3条不同种类设备的最新数据

WITH years AS (
  select to_char(years) year from 
(select TO_CHAR(Sysdate, 'YYYY') - level + 1 years from dual connect by level <= 3)
), types AS (
  SELECT '调试台设备数量' AS 设备种类, '01' AS EQUIPMENT_TYPE FROM dual
  UNION ALL
  SELECT '电装标贴设备数量' AS 设备种类, '02' AS EQUIPMENT_TYPE FROM dual
  UNION ALL
  SELECT '震动台设备数量' AS 设备种类, '03' AS EQUIPMENT_TYPE FROM dual
)
SELECT 
  a.year AS 年份,
  t.设备种类,
  NVL(b.设备总数, 0) AS 设备总数,
  NVL(b.发生故障的设备数量, 0) AS 发生故障的设备数量,
  NVL(b.发生故障总数, 0) AS 发生故障总数,
  NVL(b.设备完好率, 0) AS 设备完好率,
  NVL(b.设备停机率, 0) AS 设备停机率
FROM years a
CROSS JOIN types t
LEFT JOIN (
  SELECT 
    EQUIPMENT_TYPE,
    STAT_TIME  AS 数据日期,
    EQUIPMENT_FAILURE_TOTAL AS 设备总数,
    EQUIPMENT_FAILURE_NUM AS 发生故障的设备数量,
    EQUIPMENT_FAILURE_TOTAL AS 发生故障总数,
    EQUIPMENT_UPTIME AS 设备完好率,
    EQUIPMENT_FAILURE_DOWNTIMERATE AS 设备停机率
  FROM BRAIN.DM_EQUIPMENT_FAILURE_METRIC
  WHERE EQUIPMENT_TYPE IN ('01', '02', '03')
) b ON 
t.EQUIPMENT_TYPE = b.EQUIPMENT_TYPE 
AND a.year = b.数据日期 
AND t.设备种类 = 
CASE t.EQUIPMENT_TYPE 
WHEN '01' 
THEN '调试台设备数量' 
WHEN '02' THEN '电装标贴设备数量' 
WHEN '03' THEN '震动台设备数量' 
END
WHERE a.year =  ${年度}

9:设备故障率

SELECT
A.month AS 月份,
NVL(B.调试台故障率,0) AS 调试台故障率,
NVL(B.震动台故障率,0) AS 震动台故障率,
NVL(B.电装标贴故障率,0) AS 电装标贴故障率,
 ${年度}  AS 统计日期
from(
SELECT
  TO_CHAR(ADD_MONTHS(TO_DATE(CONCAT(   ${年度}    ,'0101'), 'YYYYMMDD'), LEVEL - 1), 'mm') || '月' AS month
FROM DUAL CONNECT BY LEVEL <= 12
) A
left join 
(
SELECT 
  NVL(DEBUG_EQUIPMENT_FAILURERATE,0) AS 调试台故障率,
  NVL(SHAKING_EQUIPMENT_FAILURERATE,0) AS 震动台故障率,
  NVL(STICKER_EQUIPMENT_FAILURERATE,0) AS 电装标贴故障率,
  SUBSTR(STAT_TIME,1,4) AS 统计日期,
  SUBSTR (STAT_TIME,5,6)|| '月'  AS 每年月份
  FROM BRAIN.DM_EQUIPMENT_GZTJV_TREND
 WHERE  SUBSTR(STAT_TIME,1,4) =     ${年度} 
 ) 
B 
ON A.month = B.每年月份
ORDER BY 月份 ASC

运行结果:

1456bb04eaee426098f5efdc90df7993.png

10:设备利用率

SELECT
 ${年度}  AS 统计日期,
A.month AS 月份,
NVL(B.调试台利用率,0) AS 调试台利用率,
NVL(B.震动台利用率,0) AS 震动台利用率,
NVL(B.电装标贴利用率,0) AS 电装标贴利用率
from(
SELECT
  TO_CHAR(ADD_MONTHS(TO_DATE(CONCAT( ${年度}    ,'0101'), 'YYYYMMDD'), LEVEL - 1), 'mm') || '月' AS month
FROM DUAL CONNECT BY LEVEL <= 12) A
left join 
(SELECT 
  NVL(COMMISSION_BENCH_OCCUPANCY,0) AS 调试台利用率,
  NVL(VIBRATION_TABLE_OCCUPANCY,0) AS 震动台利用率,
  NVL(DENSO_OCCUPANCY,0) AS 电装标贴利用率,
  SUBSTR(STAT_TIME,1,4) AS 统计日期,
  SUBSTR (STAT_TIME,5,6)|| '月'  AS 每年月份
  FROM BRAIN.DM_EQUIPMENT_OCCUPANCY
WHERE  SUBSTR(STAT_TIME,1,4) =     ${年度}    ) 
B 
ON A.month = B.每年月份
ORDER BY 月份 ASC

结果:

656fb820652a47f792a768ccd9561b3c.png

11:设备故障指标统计

SELECT 
A.年份 AS 年份,
NVL(B.电装表贴设备总数,0) AS  电装表贴设备总数,
NVL(B.调试台设备总数,0) AS 调试台设备总数,
NVL(B.振动台设备总数,0) AS 振动台设备总数,
NVL(B.电装表贴设备发生故障设备数量,0) AS 电装表贴设备发生故障设备数量,
NVL(B.调试台设备发生故障的设备数量,0) AS 调试台设备发生故障的设备数量,
NVL(B.振动台设备发生故障的设备数量,0) AS 振动台设备发生故障的设备数量,
NVL(B.电装表贴发生故障总数,0) AS 电装表贴发生故障总数,
NVL(B.调试台发生故障总数,0) AS 调试台发生故障总数,
NVL(B.振动台发生故障总数,0) AS 振动台发生故障总数,
NVL(B.设备完好率,0) AS 设备完好率,         --round(NVL(B.设备完好率,0),4)  AS 设备完好率
NVL(B.设备停机率,0) AS  设备停机率         --round(NVL(B.设备停机率,0),4)  AS 设备停机率
FROM (
select to_char(years) 年份 from (
select TO_CHAR(Sysdate, 'YYYY') - level + 1 years 
from dual connect by level <= 3)
) A 
LEFT JOIN (
SELECT 
NVL(DZBT_TOTAL_NUM,0) AS 电装表贴设备总数,
NVL(TST_TOTAL_NUM,0)  AS 调试台设备总数,
NVL(ZDT_TOTAL_NUM,0)  AS 振动台设备总数,
NVL(DZBT_FAILURE_NUM,0) AS 电装表贴设备发生故障设备数量,
NVL(TST_FAILURE_NUM,0)  AS 调试台设备发生故障的设备数量,
NVL(ZDT_FAILURE_NUM,0)  AS 振动台设备发生故障的设备数量,
NVL(DZBT_FAILURE_TOTAL,0) AS 电装表贴发生故障总数,
NVL(TST_FAILURE_TOTAL,0)  AS 调试台发生故障总数,
NVL(ZDT_FAILURE_TOTAL,0)  AS 振动台发生故障总数,
NVL(EQUIPMENT_UPTIME,0)   AS 设备完好率,
NVL(EQUIPMENT_FAILURE_DOWNTIMERATE,0) AS 设备停机率,
NVL(STAT_TIME,0)  AS 统计日期
FROM BRAIN.DM_EQUIPMENT_FAILURE_METRIC
) B
ON A.年份  = B.统计日期
WHERE A.年份= ${年度}

运行结果:

145aa6c6dec149cfb0f0aad5991f711d.png

12:工人设备汇总--解决了表管理数据重复问题

SELECT 
'' AS 唯一标识,
a.单位编号 ,
'0'  AS 是否汇总,
'04' AS 数据密度, 
NVL(a.工人总数,0) AS 工人总数,
NVL(b.电装表贴数量,0) AS 电装表贴数量,
NVL(b.调试台数量,0) AS 调试台数量,
NVL(b.振动台数量,0) AS 振动台数量,
NVL(a.数据日期,SYSDATE) AS 数据日期,
NVL(a.统计日期,SYSDATE) AS 统计日期
FROM (
--DS_WOKER_WORK_HOUR_INFO 工人工时信息表 的每年最新数据
--DS_WOKER_WORK_HOUR_INFO 工人工时信息表 的每年最新数据
SELECT 
a.ORG_NO AS 单位编号,
NVL(a.WOKER_TOTAL_NUM,0) AS 工人总数 ,
NVL(a.DATA_DATE,SYSDATE) AS 数据日期,
NVL(a.CREATE_TIME,SYSDATE) AS 统计日期
  FROM (SELECT ROW_NUMBER() OVER(PARTITION BY ORG_NO,TO_CHAR(DATA_DATE, 'YYYY') 
ORDER BY DATA_DATE DESC, CREATE_TIME DESC) rn,
               ORG_NO,
               NVL(WOKER_TOTAL_NUM,0) AS WOKER_TOTAL_NUM,
               DATA_DATE,
               CREATE_TIME
          FROM BRAIN.DS_WOKER_WORK_HOUR_INFO
) a
 where a.rn = 1) a
lEFT JOIN 
 (--DS_PRODUCT_EQUIP_INFO-生产设备信息 每年最新数据
SELECT 
a.ORG_NO AS 单位编号,
NVL(a.DENSO_NUM,0) AS 电装表贴数量,
NVL(a.COMMISSION_BENCH_NUM,0) AS 调试台数量,
NVL(a.VIBRATION_TABLE_NUM,0) AS 振动台数量,
NVL(a.DATA_DATE,SYSDATE) AS DATA_DATE
  FROM (SELECT ROW_NUMBER() OVER(PARTITION BY ORG_NO,TO_CHAR(DATA_DATE, 'YYYY') 
ORDER BY DATA_DATE DESC, CREATE_TIME DESC) rn,
               ORG_NO,
               NVL(DENSO_NUM,0) AS DENSO_NUM,  
               NVL(COMMISSION_BENCH_NUM,0) AS COMMISSION_BENCH_NUM,
               NVL(VIBRATION_TABLE_NUM,0) AS VIBRATION_TABLE_NUM,
               DATA_DATE
          FROM BRAIN.DS_PRODUCT_EQUIP_INFO
) a
 where a.rn = 1
) b
 ON a.单位编号 = b.单位编号  AND TO_CHAR(a.数据日期,'YYYY') = TO_CHAR(b.DATA_DATE,'YYYY')

运行结果:

071051c19e0d42db8a950cd2db7c7272.png

13:多种计算求结果

SELECT 
'04' AS 数据粒度,
NVL(最长工序耗时,0) AS 最长工序耗时,
NVL(平均工序耗时,0) AS 平均工序耗时,
DECODE(最长工序耗时, 0, 0, 
        CASE WHEN 最长工序耗时 = 平均工序耗时 THEN 100
             ELSE ROUND( NVL(平均工序耗时, 0) / 最长工序耗时 , 2) * 100
        END
) AS 线平衡率 ,
DECODE(COALESCE(最长工序耗时, 0), 0, 0, ROUND(20.83 * 24 * 60 / COALESCE(最长工序耗时, 0), 2)) AS 月度产能,
(1- DECODE(最长工序耗时, 0, 0, 
        CASE WHEN 最长工序耗时 = 平均工序耗时 THEN 1
             ELSE ROUND(NVL(平均工序耗时, 0) / 最长工序耗时 , 2)
        END
) ) * 100 AS  平衡损失率,
NVL(模件电裝单人工作耗时,0) AS 模件电裝单人工作耗时,
NVL(整机电裝单人工作耗时,0) AS 整机电裝单人工作耗时,
NVL(单机调试单人工作耗时,0) AS 单机调试单人工作耗时,
NVL(单板调试单人工作耗时,0) AS 单板调试单人工作耗时,
NVL(测发控系统联调单人工作耗时,0) AS 测发控系统联调单人工作耗时,
NVL(控制系统联调单人工作耗时,0) AS 控制系统联调单人工作耗时,
NVL(数据日期,SYSDATE) AS 数据日期,
NVL(统计日期,SYSDATE) AS 统计日期
FROM (
SELECT 
 GREATEST(
  NVL(a.模件电裝单人工作耗时,0),
  NVL(a.整机电裝单人工作耗时,0),
  NVL(a.单机调试单人工作耗时,0),
  NVL(a.单板调试单人工作耗时,0),
  NVL(a.测发控系统联调单人工作耗时,0),
  NVL(a.控制系统联调单人工作耗时,0)
  ) AS  最长工序耗时,
 ROUND((NVL(a.模件电裝单人工作耗时,0) + NVL(a.整机电裝单人工作耗时,0) + NVL(a.单机调试单人工作耗时,0) + NVL(a.单板调试单人工作耗时,0) + NVL(a.测发控系统联调单人工作耗时,0) + NVL(a.控制系统联调单人工作耗时,0))/6,2) AS 平均工序耗时,
 NVL(a.模件电裝单人工作耗时,0) AS 模件电裝单人工作耗时,
 NVL(a.整机电裝单人工作耗时,0) AS 整机电裝单人工作耗时,
 NVL(a.单机调试单人工作耗时,0) AS 单机调试单人工作耗时,
 NVL(a.单板调试单人工作耗时,0) AS 单板调试单人工作耗时,
 NVL(a.测发控系统联调单人工作耗时,0) AS 测发控系统联调单人工作耗时,
 NVL(a.控制系统联调单人工作耗时,0) AS 控制系统联调单人工作耗时,
 NVL(a.数据日期,SYSDATE)   AS 数据日期,
 NVL(a.CREATE_TIME,SYSDATE)   AS 统计日期
  FROM (
  SELECT ROW_NUMBER() OVER(PARTITION BY ORG_NO,TO_CHAR(DATA_DATE, 'YYYY') 
ORDER BY DATA_DATE DESC, CREATE_TIME DESC) rn,
 DECODE(MODEL_ELEC_INSTAL_NUM ,0,0,
            CASE WHEN MODEL_ELEC_INSTAL_TIME = MODEL_ELEC_INSTAL_NUM THEN 100
            ELSE ROUND(NVL(MODEL_ELEC_INSTAL_TIME,0) /  MODEL_ELEC_INSTAL_NUM ,2 )* 100 END ) AS 模件电裝单人工作耗时,
 DECODE(ELEC_INSTAL_NUM ,0,0,
                 CASE WHEN ELEC_INSTAL_TIME = ELEC_INSTAL_NUM THEN 100
            ELSE ROUND(NVL(ELEC_INSTAL_TIME,0) /  ELEC_INSTAL_NUM,2 ) * 100 END ) AS 整机电裝单人工作耗时,
 DECODE(SINGLE_TEST_NUM ,0,0,
                 CASE WHEN SINGLE_TEST_TIME = SINGLE_TEST_NUM THEN 100
            ELSE ROUND(NVL(SINGLE_TEST_TIME,0) / SINGLE_TEST_NUM ,2 ) * 100 END ) AS  单机调试单人工作耗时,
 DECODE(BOARD_TEST_NUM ,0,0,
                 CASE WHEN BOARD_TEST_TIME = BOARD_TEST_NUM THEN 100
            ELSE ROUND(NVL(BOARD_TEST_TIME,0) / BOARD_TEST_NUM,2 ) * 100   END ) AS 单板调试单人工作耗时,
 DECODE(TEST_CONTROL_SYS_NUM ,0,0,
                 CASE WHEN TEST_CONTROL_SYS_TIME = TEST_CONTROL_SYS_NUM THEN 100
            ELSE ROUND(NVL(TEST_CONTROL_SYS_TIME,0) / TEST_CONTROL_SYS_NUM ,2) * 100 END) AS 测发控系统联调单人工作耗时,
 DECODE(CONTROL_SYS_NUM ,0,0,
                 CASE WHEN CONTROL_SYS_TIME = CONTROL_SYS_NUM THEN 100
            ELSE ROUND(NVL(CONTROL_SYS_TIME,0) / CONTROL_SYS_NUM,2) * 100 END) AS 控制系统联调单人工作耗时,
          DATA_DATE AS 数据日期,
          CREATE_TIME 
          FROM BRAIN.DS_PROD_PROC_RECORD
         ) a
 where a.rn = 1
)

结果:

9579372c426d4ae2928e68e3e3807dbc.png


目录
相关文章
|
2天前
|
SQL 存储 关系型数据库
【MySQL基础篇】全面学习总结SQL语法、DataGrip安装教程
本文详细介绍了MySQL中的SQL语法,包括数据定义(DDL)、数据操作(DML)、数据查询(DQL)和数据控制(DCL)四个主要部分。内容涵盖了创建、修改和删除数据库、表以及表字段的操作,以及通过图形化工具DataGrip进行数据库管理和查询。此外,还讲解了数据的增、删、改、查操作,以及查询语句的条件、聚合函数、分组、排序和分页等知识点。
【MySQL基础篇】全面学习总结SQL语法、DataGrip安装教程
|
7天前
|
SQL Oracle 数据库
使用访问指导(SQL Access Advisor)优化数据库业务负载
本文介绍了Oracle的SQL访问指导(SQL Access Advisor)的应用场景及其使用方法。访问指导通过分析给定的工作负载,提供索引、物化视图和分区等方面的优化建议,帮助DBA提升数据库性能。具体步骤包括创建访问指导任务、创建工作负载、连接工作负载至访问指导、设置任务参数、运行访问指导、查看和应用优化建议。访问指导不仅针对单条SQL语句,还能综合考虑多条SQL语句的优化效果,为DBA提供全面的决策支持。
29 11
|
21天前
|
SQL 关系型数据库 MySQL
MySQL导入.sql文件后数据库乱码问题
本文分析了导入.sql文件后数据库备注出现乱码的原因,包括字符集不匹配、备注内容编码问题及MySQL版本或配置问题,并提供了详细的解决步骤,如检查和统一字符集设置、修改客户端连接方式、检查MySQL配置等,确保导入过程顺利。
|
20天前
|
SQL 监控 安全
SQL Servers审核提高数据库安全性
SQL Server审核是一种追踪和审查SQL Server上所有活动的机制,旨在检测潜在威胁和漏洞,监控服务器设置的更改。审核日志记录安全问题和数据泄露的详细信息,帮助管理员追踪数据库中的特定活动,确保数据安全和合规性。SQL Server审核分为服务器级和数据库级,涵盖登录、配置变更和数据操作等事件。审核工具如EventLog Analyzer提供实时监控和即时告警,帮助快速响应安全事件。
|
1月前
|
SQL 关系型数据库 MySQL
体验使用DAS实现数据库SQL优化,完成任务可得羊羔绒加厚坐垫!
本实验介绍如何通过数据库自治服务DAS对RDS MySQL高可用实例进行SQL优化,包含购买RDS实例并创建数据库、数据导入、生成并优化慢SQL、执行优化后的SQL语句等实验步骤。完成任务,即可领取羊羔绒加厚坐垫,限量500个,先到先得。
151 12
|
27天前
|
SQL 存储 BI
gbase 8a 数据库 SQL合并类优化——不同数据统计周期合并为一条SQL语句
gbase 8a 数据库 SQL合并类优化——不同数据统计周期合并为一条SQL语句
|
27天前
|
SQL 数据库
gbase 8a 数据库 SQL优化案例-关联顺序优化
gbase 8a 数据库 SQL优化案例-关联顺序优化
|
1月前
|
SQL Java 数据库连接
canal-starter 监听解析 storeValue 不一样,同样的sql 一个在mybatis执行 一个在数据库操作,导致解析不出正确对象
canal-starter 监听解析 storeValue 不一样,同样的sql 一个在mybatis执行 一个在数据库操作,导致解析不出正确对象
|
2月前
|
存储 Oracle 关系型数据库
Oracle数据库的应用场景有哪些?
【10月更文挑战第15天】Oracle数据库的应用场景有哪些?
200 64
|
16天前
|
存储 Oracle 关系型数据库
数据库数据恢复—ORACLE常见故障的数据恢复方案
Oracle数据库常见故障表现: 1、ORACLE数据库无法启动或无法正常工作。 2、ORACLE ASM存储破坏。 3、ORACLE数据文件丢失。 4、ORACLE数据文件部分损坏。 5、ORACLE DUMP文件损坏。
63 11

推荐镜像

更多