zoukankan      html  css  js  c++  java
  • mysql函数

    DROP FUNCTION IF EXISTS `getOpPassRate`;
    DELIMITER ;;
    CREATE  FUNCTION `getOpPassRate`(batchNo varchar(200) , opUrl varchar(200)) RETURNS varchar(200) CHARSET utf8
    BEGIN
    DECLARE opPassRateStr varchar(200);
    DECLARE opPassRate decimal(16,8);
    IF opUrl = 'JR'
        THEN set opPassRate = (select count(1) from TT_WO_NAKED_CELL twnc where twnc.BATCH_NO = batchNo and twnc.DEL_FLAG != '1')/((select count(1) from TT_WO_NAKED_CELL twnc where twnc.BATCH_NO = batchNo and twnc.DEL_FLAG != '1') + (select sum(twbs.SCRAP_QTY) from tt_wo_batch_scrap twbs where twbs.BATCH_NO = batchNo and twbs.OP_ID = (select top.PK_ID from tm_operation top where top.OPERATE_URL = opUrl) and twbs.DEL_FLAG != '1'));
    ELSEIF opUrl = 'RK'
        THEN set opPassRate = (select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.RK_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a)/((select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.RK_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a) + (select sum(twbs.SCRAP_QTY) from tt_wo_batch_scrap twbs where twbs.BATCH_NO = batchNo and twbs.OP_ID = (select top.PK_ID from tm_operation top where top.OPERATE_URL = opUrl) and twbs.DEL_FLAG != '1'));
    ELSEIF opUrl = 'DGHJ'
        THEN set opPassRate = (select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.DGHJ_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a)/((select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.DGHJ_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a) + (select sum(twbs.SCRAP_QTY) from tt_wo_batch_scrap twbs where twbs.BATCH_NO = batchNo and twbs.OP_ID = (select top.PK_ID from tm_operation top where top.OPERATE_URL = opUrl) and twbs.DEL_FLAG != '1'));
    ELSEIF opUrl = 'DXHK'
        THEN set opPassRate = (select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.DXHK_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a)/((select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.DXHK_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a) + (select sum(twbs.SCRAP_QTY) from tt_wo_batch_scrap twbs where twbs.BATCH_NO = batchNo and twbs.OP_ID = (select top.PK_ID from tm_operation top where top.OPERATE_URL = opUrl) and twbs.DEL_FLAG != '1'));
    ELSEIF opUrl = 'YCZY'
        THEN set opPassRate = (select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.YCZY_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a)/((select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.YCZY_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a) + (select sum(twbs.SCRAP_QTY) from tt_wo_batch_scrap twbs where twbs.BATCH_NO = batchNo and twbs.OP_ID = (select top.PK_ID from tm_operation top where top.OPERATE_URL = opUrl) and twbs.DEL_FLAG != '1'));
    ELSEIF opUrl = 'HC'
        THEN set opPassRate = (select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.HC_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a)/((select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.HC_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a) + (select sum(twbs.SCRAP_QTY) from tt_wo_batch_scrap twbs where twbs.BATCH_NO = batchNo and twbs.OP_ID = (select top.PK_ID from tm_operation top where top.OPERATE_URL = opUrl) and twbs.DEL_FLAG != '1'));
    ELSEIF opUrl = 'ECZY'
        THEN set opPassRate = (select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.ECZY_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a)/((select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.ECZY_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a) + (select sum(twbs.SCRAP_QTY) from tt_wo_batch_scrap twbs where twbs.BATCH_NO = batchNo and twbs.OP_ID = (select top.PK_ID from tm_operation top where top.OPERATE_URL = opUrl) and twbs.DEL_FLAG != '1'));
    ELSEIF opUrl = 'FR'
        THEN set opPassRate = (select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.FR_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a)/((select count(1) from (select twc.CELL_CODE from tt_wo_cell twc where twc.FR_EQUIP_CODE is not null and twc.DEL_FLAG != '1' group by twc.CELL_CODE) a) + (select sum(twbs.SCRAP_QTY) from tt_wo_batch_scrap twbs where twbs.BATCH_NO = batchNo and twbs.OP_ID = (select top.PK_ID from tm_operation top where top.OPERATE_URL = opUrl) and twbs.DEL_FLAG != '1'));
    ELSE
    set opPassRate = (select sum(tww.FINISH_QTY) from tt_wo_wip tww where tww.BATCH_NO = batchNo and tww.OP_ID = (select top.PK_ID from tm_operation top where top.OPERATE_URL = opUrl) and tww.DEL_FLAG != '1')/((select sum(tww.FINISH_QTY) from tt_wo_wip tww where tww.BATCH_NO = batchNo and tww.OP_ID = (select top.PK_ID from tm_operation top where top.OPERATE_URL = opUrl) and tww.DEL_FLAG != '1') + (select sum(twbs.SCRAP_QTY) from tt_wo_batch_scrap twbs where twbs.BATCH_NO = batchNo and twbs.OP_ID = (select top.PK_ID from tm_operation top where top.OPERATE_URL = opUrl) and twbs.DEL_FLAG != '1'));
    END IF;
    IF opPassRate is not null
        then set opPassRateStr = FORMAT(opPassRate*100,2);
    END IF;
    RETURN opPassRateStr;
    END
    ;;

  • 相关阅读:
    SAP training scope SAP从入门到精通课程体系
    萨提亚·纳德拉
    说说为什么不再写博客了
    课上用过的Linux命令
    中国商用密码生产企业和商用密码产品及标准
    在Python中运行gmssl
    基于CMPP协议集成短信测试桩全流程实践分享 做梦的人
    mysqlslap: Error when connecting to server: 1064 Reach limit of connections 做梦的人
    大数据清洗表中没有找到对应表 做梦的人
    自动生成镜像,在上传到仓库 做梦的人
  • 原文地址:https://www.cnblogs.com/cdcr/p/9438011.html
Copyright © 2011-2022 走看看