select DISTINCT COLLECT_TIME, PERF_VALUE, t1.unit, RULEA, RULEB, RULEC, EQP_OBJ_ID, tar.OBJECT_ID from ( select COLLECT_TIME, PERF_VALUE, UNIT as unit, EQP_OBJ_ID, OBJECT_TYPE, INDEX_TYPE, DEVICE_ID, INDEX_NAME from t_perf_sensor_history tpsh, t_perf_defined tpd where PERF_OBJ_ID = tpd.OBJ_ID ) as t1 left join t_alarm_rule tar on IF(tar.ALARM_OBJECT_TYPE = t1.DEVICE_ID, tar.ALARM_OBJECT_TYPE = t1.DEVICE_ID, tar.ALARM_OBJECT_TYPE = OBJECT_TYPE) where 1=1 and COLLECT_TIME BETWEEN DATE_SUB(NOW(), INTERVAL 1 DAY) AND NOW() and EQP_OBJ_ID = '30625d79-56ae-4576-b278-24a7a1684856' and INDEX_NAME = '距离' 加上判断EQP_OBJ_ID, tar.OBJECT_ID是否相等
时间: 2023-10-03 08:05:31 浏览: 87
如果要加上判断EQP_OBJ_ID和tar.OBJECT_ID是否相等,可以使用一个子查询来先去重,然后再加上判断条件。例如:
```
SELECT COLLECT_TIME, PERF_VALUE, unit, RULEA, RULEB, RULEC, EQP_OBJ_ID, OBJECT_ID
FROM (
SELECT DISTINCT t1.COLLECT_TIME, t1.PERF_VALUE, t1.unit, t1.RULEA, t1.RULEB, t1.RULEC, t1.EQP_OBJ_ID, tar.OBJECT_ID
FROM (
SELECT COLLECT_TIME, PERF_VALUE, UNIT AS unit, EQP_OBJ_ID, OBJECT_TYPE, INDEX_TYPE, DEVICE_ID, INDEX_NAME
FROM t_perf_sensor_history tpsh, t_perf_defined tpd
WHERE PERF_OBJ_ID = tpd.OBJ_ID
) AS t1
LEFT JOIN t_alarm_rule tar ON IF(tar.ALARM_OBJECT_TYPE = t1.DEVICE_ID, tar.ALARM_OBJECT_TYPE = t1.DEVICE_ID, tar.ALARM_OBJECT_TYPE = OBJECT_TYPE)
WHERE COLLECT_TIME BETWEEN DATE_SUB(NOW(), INTERVAL 1 DAY) AND NOW()
AND EQP_OBJ_ID = '30625d79-56ae-4576-b278-24a7a1684856'
AND INDEX_NAME = '距离'
) AS t2
WHERE EQP_OBJ_ID = OBJECT_ID;
```
这样可以先用子查询将EQP_OBJ_ID和OBJECT_ID去重,然后再筛选出相等的记录。
阅读全文