我有两个独立工作的查询;我需要结合这些结果。
wdate
和Empid
,从Fromdate
到ToDate
。Efc
和wdate
计算一个值(效率Empid
)。 第一个查询
SELECT *
FROM tblProductionEffcyDetails
WHERE wDate BETWEEN '06/26/2019' AND '07/25/2019'
AND worker = 'Techn'
ORDER BY Empid, wDate
第二次查询
SELECT Cast(ROUND(SUM(Tstdmin) / NULLIF(SUM(TAvlblmin), 0) * 100,0) as int) AS [Efc]
FROM tblProductionEffcyDetails
WHERE wDate='07/11/2019'
AND Empid='00021'
GROUP BY wdate, Empid
也就是说,在第二个查询中,wDate
和Empid
的值应该来自第一个查询的结果。
关于数据/表的注释:
wDate
)或个人(Empid
)可以有任何数字
的条目。 Efc
)
(wDate
),即特定wDate
不应有多个值。表结构如下
SL wDate Avlbl_Mins NP_Mins Empid Name Process Model Efc
117571 7/13/2019 0 0 21 MARRY Block removing 900-2930 80
117572 7/13/2019 0 0 21 MARRY Microscope checking 900-2929 Null
116872 6/26/2019 430 75 52 SUGANTHI Slab removing 900-2929 75
116873 6/26/2019 0 0 52 SUGANTHI Slab Removing 900-2528 Null
答案 0 :(得分:0)
尝试一下
您可以使用第一个查询来获得Empid
和06/26/2019
之间日期的特定07/25/2019
设置,并将其连接到第二个查询就可以对其进行总结。
SELECT Empid, Cast(ROUND(SUM(Tstdmin) / NULLIF(SUM(TAvlblmin), 0) * 100,0) as int) AS [Efc]
FROM tblProductionEffcyDetails t
WHERE t.Empid in (
SELECT Empid
FROM tblProductionEffcyDetails tb
WHERE tb.wDate BETWEEN '06/26/2019' AND '07/25/2019'
AND tb.worker = 'Techn') and t.wDate BETWEEN '06/26/2019' AND '07/25/2019'
GROUP BY t.wdate, t.Empid
我在了解您的问题的情况下进行了查询,请告知它是否未获得所需的输出。所以我可以更改答案。
希望这会有所帮助。
答案 1 :(得分:0)
SELECT Empid, Cast(ROUND(SUM(Tstdmin) / NULLIF(SUM(TAvlblmin), 0) * 100,0) as
int) AS [Efc]
FROM (
SELECT *
FROM tblProductionEffcyDetails tb1
WHERE tb1.wDate BETWEEN '06/26/2019' AND '07/25/2019'
AND tb1.worker = 'Techn') as t
GROUP BY t.wdate, t.Empid