查询结果当临时表
SELECT r.src_metric, r.expression, r.threshold, r.level, r.resgroup_code
FROM delta24_alarmrule r, (
SELECT resgroup_code, src_metric, COUNT(*) AS c
FROM delta24_alarmrule
WHERE yn = 0
GROUP BY resgroup_code, src_metric
) temp
WHERE r.yn = 0
AND r.resgroup_code = temp.resgroup_code
AND r.src_metric = temp.src_metric
AND temp.c = 2
ORDER BY r.resgroup_code, r.src_metric, r.level DESC
解释说明:
- (
SELECT resgroup_code, src_metric, COUNT(*) AS c
FROM delta24_alarmrule
WHERE yn = 0
GROUP BY resgroup_code, src_metric
) temp 就是把内部临时查询结果当做表temp - 然后delta24_alarmrule表和临时表temp做内连接