# coding: utf-8

# In[ ]:

WITH List AS (
SELECT e.*,f.* FROM
( SELECT DISTINCT c.lot_id, c.wafer_key,
LEFT(c.layer_id, CHARINDEX('_', c.layer_id) -1) as Layer,c.layer_id,
COUNT(0) AS defect_count,d.class_number, REPLACE(LTRIM(REPLACE(c.wafer_id, '0', ' ')), ' ', '0') as waferid
FROM [SSMC_IEDA].[dbo].[insp_wafer_summary] AS c, [SSMC_IEDA].[dbo].[insp_defect] AS d
where c.wafer_key = d.wafer_key and c.layer_id like '[CTM-M]%_ASI' and c.inspection_date BETWEEN '2018-11-01' AND '2018-11-20'
AND d.class_number in (167, 67)
GROUP BY c.lot_id,c.wafer_id,d.class_number,c.layer_id, c.wafer_key) AS e INNER JOIN
(select distinct a.recpid, a.stage, a.lotid, b.automatedrecipeid, LEFT(a.stage, CHARINDEX('_', a.stage) -1) as Stg from mes_tbl_hist AS a
INNER JOIN mes_tbl_recp AS b ON a.recpid = b.recpid WHERE a.eqpid LIKE 'AEM2%' AND a.stage NOT LIKE 'REWORK') AS f ON e.lot_id = f.lotid
AND (((e.Layer = 'CTM' OR e.Layer LIKE 'CTM%') AND (f.Stg = 'CTM' OR f.Stg LIKE 'CTM%'))
OR
(e.Layer LIKE 'M%' AND f.Stg LIKE CONCAT(substring(e.Layer, PatIndex('%[a-z]%',LOWER(e.Layer)), case PatIndex('%[a-z]%',LOWER(e.Layer)) when 0 then 2 else 1 end),'E',substring(e.Layer, PatIndex('%[0-9]%', e.Layer),case PatIndex('%[0-9]%',e.Layer) when 0 then 2 else 1 end),'%')
))
AND f.Stg NOT LIKE 'MW%'
AND f.Stg NOT LIKE 'MT%'
AND e.Layer NOT LIKE 'MT%'
AND e.Layer NOT LIKE 'MW%' )
SELECT DISTINCT List.layer_id,List.defect_count,b.eqpid, SUBSTRING(b.ParameterName, CHARINDEX('-', b.parametername) +1,1) as Chamber,
b.lotid,a.slotid,
a.waferid,
LEFT(b.ParameterName, CHARINDEX('-', b.ParameterName) -1) as Param_Name,
LEFT(c.stage, CHARINDEX('_', c.stage) -1) as Stg,
c.stage,
SUBSTRING(b.ParameterName, CHARINDEX('-', b.parametername) +3,+1) as Step,
SUBSTRING(b.ParameterName, CHARINDEX('-', b.parametername) +5, LEN( b.parametername)) as Recipie_Name,
b.parametername,
a.[data] as data1,a.finishtime,
rank() OVER (PARTITION BY a.slotid, b.eqpid,b.lotid,c.stage,List.layer_id,b.parametername ORDER BY a.finishtime) AS RNK
FROM [SSMC_RTM].[dbo].[rtm_tbl_massdata] a INNER JOIN [SSMC_RTM].[dbo].[rtm_tbl_datahist] b
ON a.[datahist_fno]=b.[fno] INNER JOIN SSMC_RTM.dbo.rtm_tbl_batchdatahist c ON b.fno = c.datahist_fno
INNER JOIN List ON List.lot_id = b.lotid AND List.waferid = a.slotid AND LEFT(c.stage, CHARINDEX('_', c.stage) -1) = List.Stg
AND SUBSTRING(b.parametername, CHARINDEX('-', b.parametername) +5, LEN( b.parametername)) = List.automatedrecipeid
WHERE b.parametername LIKE '%-4-%'
--AND b.parametername NOT LIKE '%-$'
AND b.parametername LIKE '%-%-%-%'
AND ( b.parametername LIKE 'ETCM_PHA4_A%' OR b.parametername LIKE 'ETCM_PHA4_B%'
OR b.parametername LIKE 'ETCM_PHB4_A%' OR b.parametername LIKE 'ETCM_PHB4_B%'
OR b.parametername LIKE 'ETCM_PHC4_A%' OR b.parametername LIKE 'ETCM_PHC4_B%'
OR b.parametername LIKE 'HELK_MEAN_A%' OR b.parametername LIKE 'HELK_MEAN_B%'
OR b.parametername LIKE 'LOWERCHM_PRESS_A%' OR b.parametername LIKE 'LOWERCHM_PRESS_B%'
OR b.parametername LIKE 'PBK4_A%' OR b.parametername LIKE 'PBK4_B%'
OR b.parametername LIKE 'RR23_MEAN_A%' OR b.parametername LIKE 'RR23_MEAN_B%'
OR b.parametername LIKE 'RR23_MAX._A%' OR b.parametername LIKE 'RR23_MAX._B%'
OR b.parametername LIKE 'RR13_MEAN_A%' OR b.parametername LIKE 'RR13_MEAN_B%'
OR b.parametername LIKE 'RR13_MAX._A%' OR b.parametername LIKE 'RR13_MAX._B%'
OR b.parametername LIKE 'THR3_MAX._A%' OR b.parametername LIKE 'THR3_MAX._B%'
OR b.parametername LIKE 'THR3_MAX._DIFF_A%' OR b.parametername LIKE 'THR3_MAX._DIFF_B%'
OR b.parametername LIKE 'THR3_MEAN_A%' OR b.parametername LIKE 'THR3_MEAN_B%'
OR b.parametername LIKE 'THR3_MEAN_DIFF_A%' OR b.parametername LIKE 'THR3_MEAN_DIFF_B%'
OR b.parametername LIKE 'THR3_MEAN_SLOPE_A%' OR b.parametername LIKE 'THR3_MEAN_SLOPE_B%'
-- b.parametername LIKE 'BIAS_COEF_A%' OR b.parametername LIKE 'BIAS_COEF_B%'
OR b.parametername LIKE 'CURRENT_MAX._A%' OR b.parametername LIKE 'CURRENT_MAX._B%'
OR b.parametername LIKE 'CURRENT_MAX._DIFF_A%' OR b.parametername LIKE 'CURRENT_MAX._DIFF_B%'
OR b.parametername LIKE 'CURRENT_MEAN_A%' OR b.parametername LIKE 'CURRENT_MEAN_B%'
OR b.parametername LIKE 'CURRENT_MEAN_DIFF_A%' OR b.parametername LIKE 'CURRENT_MEAN_DIFF_B%'
OR b.parametername LIKE 'DCB3_MEAN_A%' OR b.parametername LIKE 'DCB3_MEAN_B%'
--OR b.parametername LIKE 'DCB3_MEAN_DIFF_A%' OR b.parametername LIKE 'DCB3_MEAN_DIFF_B%'
OR b.parametername LIKE 'DCB3_MEAN_SLOPE_A%' OR b.parametername LIKE 'DCB3_MEAN_SLOPE_B%'
OR b.parametername LIKE 'ETCM_PHA4_DIFF_A%' OR b.parametername LIKE 'ETCM_PHA4_DIFF_B%'
OR b.parametername LIKE 'ETCM_PHB4_DIFF_A%' OR b.parametername LIKE 'ETCM_PHB4_DIFF_B%'
OR b.parametername LIKE 'ETCM_PHC4_DIFF_A%' OR b.parametername LIKE 'ETCM_PHC4_DIFF_B%'
OR b.parametername LIKE 'HECL_MAX._A%' OR b.parametername LIKE 'HECL_MAX._B%'
OR b.parametername LIKE 'HECL_MEAN_A%' OR b.parametername LIKE 'HECL_MEAN_B%'
OR b.parametername LIKE 'HECL_MEAN_DIFF_A%' OR b.parametername LIKE 'HECL_MEAN_DIFF_B%'
OR b.parametername LIKE 'HECL_MIN._A%' OR b.parametername LIKE 'HECL_MIN._B%'
OR b.parametername LIKE 'HELK_MEAN_DIFF_A%' OR b.parametername LIKE 'HELK_MEAN_DIFF_B%'
OR b.parametername LIKE 'HELK_MEAN_SLOPE_A%' OR b.parametername LIKE 'HELK_MEAN_SLOPE_B%'
OR b.parametername LIKE 'LOWERCHM_PRESS_DIFF_A%' OR b.parametername LIKE 'LOWERCHM_PRESS_DIFF_B%'
OR b.parametername LIKE 'PBK4_DIFF_A%' OR b.parametername LIKE 'PBK4_DIFF_B%'
OR b.parametername LIKE 'RF11_MAX._A%' OR b.parametername LIKE 'RF11_MAX._B%'
OR b.parametername LIKE 'RF11_MAX._DIFF_A%' OR b.parametername LIKE 'RF11_MAX._DIFF_B%'
OR b.parametername LIKE 'RF11_MEAN_A%' OR b.parametername LIKE 'RF11_MEAN_B%'
OR b.parametername LIKE 'RF21_MAX._A%' OR b.parametername LIKE 'RF21_MAX._B%'
OR b.parametername LIKE 'RF21_MEAN_A%' OR b.parametername LIKE 'RF21_MEAN_B%'
OR b.parametername LIKE 'RF21_MEAN_DIFF_A%' OR b.parametername LIKE 'RF21_MEAN_DIFF_B%'
--OR b.parametername LIKE 'RF21_MIN._A%' OR b.parametername LIKE 'RF21_MIN._B%'
OR b.parametername LIKE 'RF21_SD_A%' OR b.parametername LIKE 'RF21_SD_B%'
OR b.parametername LIKE 'RLD3_MEAN_A%' OR b.parametername LIKE 'RLD3_MEAN_B%'
OR b.parametername LIKE 'RLD3_MEAN_DIFF_A%' OR b.parametername LIKE 'RLD3_MEAN_DIFF_B%'
OR b.parametername LIKE 'RR13_MAX._A%' OR b.parametername LIKE 'RR13_MAX._B%'
OR b.parametername LIKE 'RR13_MAX._DIFF_A%' OR b.parametername LIKE 'RR13_MAX._DIFF_B%'
OR b.parametername LIKE 'RR23_MEAN_DIFF_A%' OR b.parametername LIKE 'RR23_MEAN_DIFF_B%'
OR b.parametername LIKE 'RR23_MEAN_SLOPE_A%' OR b.parametername LIKE 'RR23_MEAN_SLOPE_B%'
OR b.parametername LIKE 'RTN3_MEAN_A%' OR b.parametername LIKE 'RTN3_MEAN_B%'
OR b.parametername LIKE 'RTN3_MEAN_DIFF_A%' OR b.parametername LIKE 'RTN3_MEAN_DIFF_B%'
--OR b.parametername LIKE 'SOURCE_COEF_A%' OR b.parametername LIKE 'SOURCE_COEF_B%'
OR b.parametername LIKE 'SRTM_A%' OR b.parametername LIKE 'SRTM_B%'
OR b.parametername LIKE 'SRTM_SLOPE_A%' OR b.parametername LIKE 'SRTM_SLOPE_B%'
OR b.parametername LIKE 'TMP1_MAX._A%' OR b.parametername LIKE 'TMP1_MAX._B%'
OR b.parametername LIKE 'TMP1_MAX._DIFF_A%' OR b.parametername LIKE 'TMP1_MAX._DIFF_B%'
OR b.parametername LIKE 'TMP1_MEAN_A%' OR b.parametername LIKE 'TMP1_MEAN_B%'
--OR b.parametername LIKE 'TMP1_MEAN_DIFF_A%' OR b.parametername LIKE 'TMP1_MEAN_DIFF_B%'
OR b.parametername LIKE 'VOLT_MAX._A%' OR b.parametername LIKE 'VOLT_MAX._B%'
--OR b.parametername LIKE 'VOLT_MAX._DIFF_A%' OR b.parametername LIKE 'VOLT_MAX._DIFF_B%'
OR b.parametername LIKE 'VOLT_MEAN_A%' OR b.parametername LIKE 'VOLT_MEAN_B%'
OR b.parametername LIKE 'VOLT_MEAN_DIFF_A%' OR b.parametername LIKE 'VOLT_MEAN_DIFF_B%'
)

我的代码-sql query的更多相关文章

  1. NHibernate系列文章二十六:NHibernate查询之SQL Query查询(附程序下载)

    摘要 NHibernate在很早的版本就提供了SQL Query(原生SQL查询),对于很复杂的查询,如果使用其他的查询方式实现比较困难的时候,一般使用SQL Query.使用SQL Query是基于 ...

  2. 使用JSTL的sql:query标签制作分页查询遇到NoSuchFieldError: deferredExpression

    参考:http://hi.baidu.com/desyle/item/4fe650265792d7182a0f1c33 症状: 如题所述,代码如下 <sql:query var="re ...

  3. jstl中的sql:query标签获取的结果如何格式化输出

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  4. .net连接DB2的异常SQL0666 - SQL query exceeds specified time limit or storage limit.错误处理

    SQL0666 - SQL query exceeds specified time limit or storage limit. 原因:查询超时 解决办法: set the DbCommand.C ...

  5. Freebie - Utility Form: Generate Excel Report From SQL Query In Oracle Forms 6i And 11g

    Sharing a form to generate Excel file report from SQL query in Oracle Forms. This form can be used i ...

  6. jasper ireport create a report with parameters without sql query

    I'm new in jasper ireport , and I want to know if it is possible to create a report only with static ...

  7. REP-20147 Cannot implement column link for this detail SQL query. Converting to group link.

    注:本文为原创,作为学习交流使用,转载请标明作者及出处,作者保留追究法律责任的权力. Lumen Su lzsu1989#gmail.com (#=@) www.cnblogs.com/lzsu198 ...

  8. EntityFramework 学习 一 Execute Native SQL Query

    SQL query for entity types: using (var ctx = new SchoolDBEntities()) { var studentList = ctx.Student ...

  9. Entity Framework Tutorial Basics(39):Raw SQL Query

    Execute Native SQL Query You can execute native raw SQL query against the database using DBContext. ...

随机推荐

  1. setTimeout代替setInterval的写法以及setInterval的弊端以及越来越快的解决办法

    平常经常遇到的一个问题,很多人想间隔时间执行一些事件的时候,第一时间就会想到用setInterval,但是setInterval村子啊不少弊端哦. 弊端1:setInterval会无视错误代码,即使代 ...

  2. rebar3自动编译

    功能:修改完代码可以自动编译加载到VM中 必须安装的软件: Linux: inotify  链接https://github.com/rvoicilas/inotify-tools/wiki 配置: ...

  3. mybatis-generator 代码自动生成工具包

    怎么用mybatis-gennerator插件自动生成mybatis所需要的dao.bean.mapper xml文件.请看↓ 1.在D盘新建一个文件夹,命名:generator(或者其他盘其他名字也 ...

  4. python基础数据类型-练习

    1,有如下变量(tu是个元祖),请实现要求的功能 tu = ("alex", [11, 22, {"k1": 'v1', "k2": [&q ...

  5. 阶段01Java基础day26反射

    27.01_反射(类的加载概述和加载时机) A:类的加载概述 当程序要使用某个类时,如果该类还未被加载到内存中,则系统会通过加载,连接,初始化三步来实现对这个类进行初始化. 加载 就是指将class文 ...

  6. JavaWeb笔记三、MVC 设计模式

    一.通过 MVC 进行查询和删除操作 1. 准备一个数据表(examstudent) 2. 创建一个 查询 页面(test.jsp) 通过连接进入 Servlet(listAllStudents.ja ...

  7. Python 天气查询到实现语音播放

    import requests #引用requests模块import pygame # 获取天气def inquery(self): url = "https://free-api.hew ...

  8. if else 和if elif else的区别

    def fuck(a): if a ==1: print(a) if a ==2: print("not good") else: print("tamade" ...

  9. 20175224 2018-2019-2 《Java程序设计》第四周学习总结

    教材学习内容总结 子类的定义 class 子类名 extends 父类名 { ... } 子类继承性 子类继承父类的成员变量.方法.成员变量可以被子类中自己定义的任何实例方法操作:继承的方法可以被子类 ...

  10. 小程序 onReachBottom 事件快速滑动时不触发的bug

    一般在列表页面 会先加载一定数量的数据 触发上拉加载这个动作的时候再陆续加载数据 假如上拉一次加载10条数据 在小程序中 你快速滑动页面触发加载这个事件的话 你会发现小程序卡着不动了 刚开始以为数据加 ...