包含报警\u 1但不包含报警\u 4的所有运行的计算机\u id和运行\u id 聚合和 having 请记住:
select machine_id, run_id
from t
where alarm_name in ('Alarm_1', 'Alarm_4')
group by machine_id, run_id
having min(alarm_name) = 'Alarm_1' and max(alarm_name) = 'Alarm_4';
SELECT t1.machine_id, t1.run_id
FROM tablename t1
WHERE t1.alarm_name = 'Alarm_1'
AND NOT EXISTS (
SELECT 1
FROM tablename t2
WHERE t2.machine_id = t1.machine_id AND t2.run_id = t1.run_id AND t2.alarm_name = 'Alarm_4'
)
2条答案
按热度按时间xzv2uavs1#
包含报警\u 1但不包含报警\u 4的所有运行的计算机\u id和运行\u id
聚合和
having
请记住:因为
'Alarm_1' <
'警报4', you can simplify the
有从句到:pod7payv2#
使用
NOT EXISTS
: