在SQL中查找没有特定值的记录

时间:2018-10-19 15:06:07

标签: sql-server

您好,我需要一个帮助来查找一个查询,该查询将从表中获取所有记录 它不包含配对警报类型,其值是“ RETURN”,另一个值是我的表:

AlarmType   Day                     PointName 
SENSOR      2017-09-02 00:00:00.000 20CHB01CE104XG95.UNIT2@NET0
RETURN      2017-09-02 00:00:00.000 20CHB01CE104XG95.UNIT2@NET0
RETURN      2017-09-02 00:00:00.000 20CHB01CE105XG95.UNIT2@NET0
SENSOR      2017-09-02 00:00:00.000 20CHB01CE105XG95.UNIT2@NET0
RETURN      2017-09-02 00:00:00.000 20CHB01CE106XG95.UNIT2@NET0
SENSOR      2017-09-02 00:00:00.000 20CHB01CE106XG95.UNIT2@NET0
RETURN      2017-09-02 00:00:00.000 20CHB01CE107XG95.UNIT2@NET0
SENSOR      2017-09-02 00:00:00.000 20CHB01CE107XG95.UNIT2@NET0

HIGH1       2017-09-02 00:00:00.000 20LBB20CP003.UNIT2@NET0

SENSOR      2017-09-02 00:00:00.000 20MAV10CL011.UNIT2@NET0

现在我要寻找的答案是最后两行,因为它们没有任何“返回”值

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:0)

尝试一下:

select *
from <table>
where pointName not in (select pointName from <table> where alarmType = 'return');

答案 1 :(得分:0)

尝试一下:

    SELECT * FROM <table> WHERE alarmtype <> 'RETURN'