SELECT SUM( CASE WHEN A.RUNLONGTIME IS NULL THEN 0 ELSE TO_NUMBER( A.RUNLONGTIME ) END ) AS 运行时间, SUM( CASE WHEN A.TOTALTIME IS NULL THEN 0 ELSE 12 END ) AS 总时间, CONCAT( CONCAT( B.SUPUSER_ID, ':' ), B.SUPUSER_NAME ) AS 技术员, ROUND(( SUM( CASE WHEN A.RUNLONGTIME IS NULL THEN 0 ELSE TO_NUMBER( A.RUNLONGTIME ) END ) / SUM( CASE WHEN A.TOTALTIME IS NULL THEN 0 ELSE 12 END )), 4 ) * 100 oee , '2023-06-26 08:00:00' AS 开始时间, '2023-06-27 08:00:00' AS 结束时间, ( CASE C.PROCESS WHEN '3' THEN '焊线A区' WHEN '5' THEN '焊线B区' WHEN '7' THEN '焊线C区' END ) AS 区域 FROM RPT_EQP_STATETIME A LEFT JOIN BAS_USEREQP_CONFIG B ON A.EQP_ID = B.EQP_ID AND A.CREATED_TIME = B.END_TIME LEFT JOIN BAS_EQP_EQUIPMENT C ON A.EQP_ID = C.EQP_ID WHERE A.EQP_ID LIKE 'WB%' AND A.CREATED_TIME > to_date( '2023-06-16 08:00:00', 'yyyy-MM-dd hh24:mi:ss' ) AND A.CREATED_TIME <= to_date( '2023-06-26 20:00:00', 'yyyy-MM-dd hh24:mi:ss' ) AND B.START_TIME >= TO_DATE( '2023-06-16 08:00:00', 'YYYY-MM-DD HH24:MI:SS' ) AND B.END_TIME <= TO_DATE( '2023-06-26 20:00:00', 'YYYY-MM-DD HH24:MI:SS' ) AND A.CREATED_TIME = B.END_TIME GROUP BY B.SUPUSER_ID, B.SUPUSER_NAME, C.PROCESS ORDER BY OEE DESC
时间: 2024-02-05 18:03:44 浏览: 99
运行时间计算
4星 · 用户满意度95%
这是一个复杂的SELECT语句,它使用了多个表的JOIN和聚合函数来生成结果集。以下是对该语句的解释:
```sql
SELECT
SUM( CASE WHEN A.RUNLONGTIME IS NULL THEN 0 ELSE TO_NUMBER( A.RUNLONGTIME ) END ) AS 运行时间,
SUM( CASE WHEN A.TOTALTIME IS NULL THEN 0 ELSE 12 END ) AS 总时间,
CONCAT( CONCAT( B.SUPUSER_ID, ':' ), B.SUPUSER_NAME ) AS 技术员,
ROUND((
SUM( CASE WHEN A.RUNLONGTIME IS NULL THEN 0 ELSE TO_NUMBER( A.RUNLONGTIME ) END ) / SUM( CASE WHEN A.TOTALTIME IS NULL THEN 0 ELSE 12 END )),
4
) * 100 oee ,
'2023-06-26 08:00:00' AS 开始时间,
'2023-06-27 08:00:00' AS 结束时间,
( CASE C.PROCESS WHEN '3' THEN '焊线A区' WHEN '5' THEN '焊线B区' WHEN '7' THEN '焊线C区' END ) AS 区域
FROM
RPT_EQP_STATETIME A
LEFT JOIN BAS_USEREQP_CONFIG B ON A.EQP_ID = B.EQP_ID
AND A.CREATED_TIME = B.END_TIME
LEFT JOIN BAS_EQP_EQUIPMENT C ON A.EQP_ID = C.EQP_ID
WHERE
A.EQP_ID LIKE 'WB%'
AND A.CREATED_TIME > to_date( '2023-06-16 08:00:00', 'yyyy-MM-dd hh24:mi:ss' )
AND A.CREATED_TIME <= to_date( '2023-06-26 20:00:00', 'yyyy-MM-dd hh24:mi:ss' )
AND B.START_TIME >= TO_DATE( '2023-06-16 08:00:00', 'YYYY-MM-DD HH24:MI:SS' )
AND B.END_TIME <= TO_DATE( '2023-06-26 20:00:00', 'YYYY-MM-DD HH24:MI:SS' )
AND A.CREATED_TIME = B.END_TIME
GROUP BY
B.SUPUSER_ID,
B.SUPUSER_NAME,
C.PROCESS
ORDER BY
OEE DESC
```
这个查询语句从表RPT_EQP_STATETIME(A)、BAS_USEREQP_CONFIG(B)和BAS_EQP_EQUIPMENT(C)中检索数据。它使用了LEFT JOIN关键字将这些表连接起来。
查询的目的是计算运行时间、总时间、技术员、OEE指数、开始时间、结束时间和区域。其中,运行时间和总时间是通过SUM函数和CASE表达式计算得出的。技术员是通过CONCAT函数将SUPUSER_ID和SUPUSER_NAME拼接而成的。OEE指数是通过运行时间除以总时间,并乘以100计算得出的。
查询还包括了一些筛选条件,例如EQP_ID的模糊匹配,CREATED_TIME的范围限制等。
最后,查询使用GROUP BY子句对SUPUSER_ID、SUPUSER_NAME和PROCESS进行分组,并使用ORDER BY子句按OEE指数降序排序结果集。
阅读全文